Link to home
Start Free TrialLog in
Avatar of jellis613
jellis613

asked on

Select a Printer in ASP.net page

I am trying to print a ReportDocument (Crystal Reports) using the ReportDocument.PrintToPrinter() function. The first parameter that this function needs is the printer name to which the document should be printed. I am trying to use the System.Windows.Forms.PrintDialog class to open up a print dialog and use it to set the printer to which the document should be printed. Here is my code:

ReportDocument rd = LoadReport(litFileName.Text); // Function to generate report document
System.Windows.Forms.PrintDialog pDlg = new System.Windows.Forms.PrintDialog();
pDlg.AllowSomePages = true;
pDlg.ShowHelp = true;

if (pDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
      rd.PrintOptions.PrinterName = pDlg.PrinterSettings.PrinterName;
      int numOfCopies = pDlg.PrinterSettings.Copies;
      rd.PrintToPrinter(numOfCopies,true,1,1);
}

When I run this code, I get the following error (thrown on the ShowDialog() method call): "It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application."

After doing some web-searching, it seems that you cannot open a Windows.Forms dialog/message box through an ASP.net application.

Is this true? If so, how can I find out the name of the user's default printer in order that I can send this to ReportDocument.PrintToPrinter()??
ASKER CERTIFIED SOLUTION
Avatar of djhex
djhex

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jellis613
jellis613

ASKER

all I need is the name of the person's default printer. Is there some way that I can parse the list of printers available for this person to use on their computer and then let the user select which printer they would like to print to?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial