We have a requirement to print html text from a service. We have used InternetExplorerClass [ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref missing, ref missing)] . The code prints the html file when in a windows application. But in a service, it is printed to the document writer instead of the printer. Are there any settings/permissions to be given when it is run as a service?
InternetExplorer ie = new InternetExplorerClass();
ie.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(ie_DocumentComplete);
ie.PrintTemplateTeardown += new DWebBrowserEvents2_PrintTemplateTeardownEventHandler(ie_PrintTemplateTeardown);
object missing = Missing.Value;
ie.Navigate(htmlFilename, ref missing, ref missing, ref missing, ref missing);
while (!documentLoaded && ie.QueryStatusWB(OLECMDID.OLECMDID_PRINT) != OLECMDF.OLECMDF_ENABLED)
Thread.Sleep(100);
ie.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref missing, ref missing);
while (!documentPrinted)
Thread.Sleep(100);
ie.DocumentComplete -= ie_DocumentComplete;
ie.PrintTemplateTeardown -= ie_PrintTemplateTeardown;
ie.Quit() ;
Loading

Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 1, 2010, 3:36 AM EDT
goto Start - > Printers & Faxes
mark the correct printer as default.
Then your problem will be solved
Sandhya Chandrasekharan10 reputationPosted Oct 1, 2010, 3:57 AM EDT
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 1, 2010, 4:05 AM EDT
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 1, 2010, 4:08 AM EDT
Sometimes that might cause an issue.
Sandhya Chandrasekharan10 reputationPosted Oct 1, 2010, 4:09 AM EDT
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 1, 2010, 4:12 AM EDT
Let me know if that solves the problem
Sandhya Chandrasekharan10 reputationPosted Oct 1, 2010, 4:35 AM EDT