We are using CR4VS2010 as part of a WinForms project. The project includes a form that uses the CrystalDecisions.Windows.Forms.CrystalReportViewer control. Our users asked for the viewer to have the viewer default to the last printer used in our application, so we added some code to set the printer name. This allows them to click the "Print" button in the viewer and have the printer automatically set to the specific printer, which may not be their default printer.
The code accesses a CrystalDecisions.CrystalReports.Engine.ReportDocument object. From that, we access the CrystalDecisions.CrystalReports.Engine.PrintOptions object, and from that we set the PrinterName property. This worked well in house. When we made the release available to our user base, our support team has been swamped with users who are getting InvalidSpecifiedPrinter exceptions on the line where we set the PrinterName property.
For some users, the problem is temporarily fixed by logging off and then logging back in their computer. For other users, the problem happens 100% of the time, but only for particular printers. We have tested SP4 and SP6, with the same symptoms on both versions.
I created a very simple test project that easily recreates the symptoms. It has a button that uses the "simple" technique we tried. It has a button that tries to set the printer by using CopyFrom with PrinterSettings and PageSettings classes. It also has a button to print directly to the printer, without involving the print preview control.
The simple button recreates the "invalid printer" error. This test project catches it (something I will be adding to our code as an interim fix).
The "printer settings" button is even less reliable than the simple set of the printer name. It constantly gets "not supported" and "index out of bounds" exceptions when referencing Duplex mode or Collation properties.
The "direct print" button seems to work 100% of the time. This is just there for demonstration, as our users don't always want to print directly to the printer. They want the preview option...
Can anybody offer advice on what I should be doing differently to get the preview control to default to the specific printer? I have attached the sample project source. It's actually a zip file, so you'll have to rename it after downloading it.
Thanks,
- Don Benson -
Tribute Inc.