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;
}
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;
}