Symptom
- The printer set at runtime is not passed to the print dialog shown by clicking the print button in CrystalReportsViewer
- Default printer in the local machine is always selected
Environment
- Crystal Reports XI
- Crystal Reports XI Release 2
- Crystal Reports 2008
- Microsoft Visual Studio .NET 2003
- Microsoft Visual Studio 2005
Reproducing the Issue
- Use the following code to set the printer at runtime before viewing the report.
Visual Basic .NET sample code:
crReportDocument.PrinterOptions.PrinterName = "name of printer"
- Run the application to display the report in CrystalReportsViewer.
- Click the print button in the viewer.
Cause
Resolution
Workaround: Use PrintToPrinter method to print the report.
Visual Basic .NET sample code for CR XI:
crReportDocument.PrinterOptions.PrinterName = "name of printer"
crReportDocument.PrintToPrinter(1, True, 1, 1)
C# sample code for CR 2008:
myRep.PrintOptions.PrinterName = "name of non default printer ""
System.Drawing.Printing.PageSettings mypage = new System.Drawing.Printing.PageSettings();
System.Drawing.Printing.PrinterSettings myprinter = new System.Drawing.Printing.PrinterSettings();
myprinter.PrinterName = myRep.PrintOptions.PrinterName;
myRep.PrintToPrinter(myprinter, mypage, false);
Keywords
CR for .NET, Crystal Reports, VS.NET, printer, dialog box, default , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem