1. Use IE to print, call Window.print (), but this approach on the page that there are reports, and other controls can not distinguish between the situation, can not achieve only the purpose of printing the report content;
2. Self-written printing code
The code is as follows:
Copy Code code as follows:
CrystalDecisions.CrystalReports.Engine.ReportDocument rd=new CrystalDecisions.CrystalReports.Engine.ReportDocument ();
Rd. Load (Server.MapPath ("crystalreport1.rpt"));
Rd. Printoptions.printername= "Printer name";
Rd. Printtoprinter (1,true,0,0);
where "printer name": In the case of a network printer, add "\ machine name" to the printer name. Local printers can also be displayed in the DropDownList control to allow the user to select:
Copy Code code as follows:
foreach (String iprt in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
This. DROPDOWNLIST1.ITEMS.ADD (IPRT);
This method can only print the contents of the report, the disadvantage is that you must indicate the printer name. If the local printer is fine, you can enumerate it and let the user choose. But if it is a network printer, it seems to be a bit of a problem, I do not know how to list the network printer to let users choose, or automatically select the default network printer.
3. Export to PDF or Excel or other format file printing. The sample code is as follows:
Report name Myrpt=new report name ();
Copy Code code as follows:
Myrpt. Exportoptions.exportdestinationtype=crystaldecisions.shared.exportdestinationtype.diskfile;
Myrpt. Exportoptions.exportformattype=crystaldecisions.shared.exportformattype.portabledocformat;
CrystalDecisions.Shared.DiskFileDestinationOptions opt=new CrystalDecisions.Shared.DiskFileDestinationOptions ();
Opt. diskfilename=@ "filename";
Myrpt. Exportoptions.destinationoptions =opt;
Myrpt. Export ();