How to setup server side printing in ASP.NET 4.0 using Crystal Reports

by Jim Cho 26. September 2011 07:32

You are trying to print in ASP.NET on a printer setup on the server using Crystal Reports. This could be a network or IP printer. The code you use might look like this simplified version:

using (ReportDocument rptDoc = new ReportDocument())
{
    rptDoc.Load(myReportPath);
    rptDoc.SetDataSource(myDataSource);
    rptDoc.PrintToPrinter(1, true, 0, 0);
}

Note that if a printer name is not specified (with PrintOptions.PrinterName), it should still print to the default printer. When you explicitly setting the printer name with PrinterOptions.PrinterName results in the same printer not found errors.

This seems to work fine when you run it from your development machine, but after you deploy your application to the server, it no longer works. The server Event Log shows an exception like the following: More...