In ASP. NET, the crystal report does not provide the report export and printing functions as in Windows form. We need to add it by ourselves. Code Here is a demo:
Export:
Myreport reportdoc = new myreport (); // table name
Private void btnexport_click (Object sender, system. eventargs E)
{
Crystaldecisions. Shared. diskfiledestinationoptions diskopts = new crystaldecisions. Shared. diskfiledestinationoptions ();
Reportdoc. exportoptions. exportdestinationtype = crystaldecisions. Shared. exportdestinationtype. diskfile;
Switch (dropdownlist1.selecteditem. Text)
{
Case "Rich Text (RTF )":
Reportdoc. exportoptions. exportformattype = crystaldecisions. Shared. exportformattype. richtext;
Diskopts. diskfilename = "d :\\ demo. rtf ";
Break;
Case "Portable Document (PDF )":
Reportdoc. exportoptions. exportformattype = crystaldecisions. Shared. exportformattype. portabledocformat;
Diskopts. diskfilename = "d :\\ demo.pdf ";
Break;
Case "MS Word (DOC )":
Reportdoc. exportoptions. exportformattype = crystaldecisions. Shared. exportformattype. wordforwindows;
Diskopts. diskfilename = "d :\\ demo.doc ";
Break;
Case "MS Excel (xls )":
Reportdoc. exportoptions. exportformattype = crystaldecisions. Shared. exportformattype. Excel;
Diskopts. diskfilename = "d :\\ demo.xls ";
Break;
Default:
Break;
}
Reportdoc. exportoptions. destinationoptions = diskopts;
Reportdoc. Export ();
}
Print:
Private void btnprint_click (Object sender, system. eventargs E)
{
String strprintername; // specify the printer name
Strprintername = @ "Canon Bubble-jet BJC-210SP ";
Pagemargins margins; // sets the print margin.
Margins = reportdoc. printoptions. pagemargins;
Margins. bottommargin = 250;
Margins. leftmargin = 350;
Margins. rightmargin = 350;
Margins. topmargin = 450;
Reportdoc. printoptions. applypagemargins (margins );
Reportdoc. printoptions. printername = strprintername; // The Name Of The application printer.
// Print the report. startpagen and endpagen
// If the parameter is set to 0, all pages are printed.
Reportdoc. printtoprinter (1, false, 0, 0 );
}