This is a migrated thread and some comments may be shown as answers.

Telerik Reporting Print Dialog Box Appears In Windows Service

6 Answers 241 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 07 Mar 2011, 12:50 PM
I am using Telerik Reporting for just printing in my windows service but what happen is that its showing a dialog box for printing and I am getting an exception. I have already defined a default printer name by my function. Any help would be greatly appreciated.

Exception :

Service cannot be started. System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.

 System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
            printerSettings.PrinterName = GetDefaultPrinter();
            Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
            System.Drawing.Printing.StandardPrintController standardPrintController = new System.Drawing.Printing.StandardPrintController();
            Telerik.Reporting.Report rpt = new Telerik.Reporting.Report();            
            reportProcessor.PrintController = standardPrintController;
            reportProcessor.PrintReport(rpt, printerSettings); 



public string GetDefaultPrinter()
        {
            System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
            foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                printerSettings.PrinterName = printer;
                if (printerSettings.IsDefaultPrinter)
                {
                    return printerSettings.PrinterName;
                    //return printer;
                }
            }
            return string.Empty;
        }

6 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 10 Mar 2011, 03:38 PM
Hi Muhammad,

Generally the error states that the Print Dialog is trying to initialize. Thus our suggestion is to test/debug your code in Windows Forms application. If the Print Dialog is initialized then most probably you don't have a default printer or you have other configuration issue.

Best wishes,
Peter
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Muhammad
Top achievements
Rank 1
answered on 10 Mar 2011, 05:10 PM
I ran my application (windows form) and still I am getting a dialog box but it's showing my default printer in the dialog box is there is some way that I can skip that dialog box. Please provide me some solution.
0
Peter
Telerik team
answered on 16 Mar 2011, 04:00 PM
Hi Muhammad,

I have attached a sample WinForms project with the code you have provided and a video to demonstrate the expected behavior. Most probably there is something specific to your printers configuration that forces the print dialog.

Best wishes,
Peter
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Muhammad
Top achievements
Rank 1
answered on 16 Mar 2011, 04:42 PM
Thank you so much ... U solved id :)
0
Swetha
Top achievements
Rank 1
answered on 02 Jul 2013, 04:47 PM
Hello Telerik Team,

I have the same problem. I tried the solution you have suggested here. But still i get the same error in the server.
It works fine in my local.
0
Stef
Telerik team
answered on 05 Jul 2013, 04:19 PM
Hello Swetha,

If the mentioned issue is the same from your other posts, please check the provided answer.

In case this is another issue, elaborate on the scenario, received error, application structure and created report definitions.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Peter
Telerik team
Muhammad
Top achievements
Rank 1
Swetha
Top achievements
Rank 1
Stef
Telerik team
Share this question
or