Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

14.14 C# Code Listings

C# Code Listings

The C# code listings are equivalent to the VB.NET code listings.

Listing 14-1. A template for modifying reports.
private void Form1_Load(object sender, System.EventArgs e)
{
CrystalReport1 MyReport = new CrystalReport1();
//Call all report modification code here.
//For illustration purposes, I'm calling a generice method that changes the report title.
//The code for ModifyTitle() isn't shown here.
ModifyTitle(MyReport, "Runtime Demo");
crystalReportViewer1.ReportSource = MyReport;
}
Listing 14-2. Template for ASP.NET pages.
private void Page_Load(object sender, System.EventArgs e)
{
CrystalDecisions.CrystalReports.Engine.ReportDocument MyReport;
if (!IsPostBack) {
MyReport = new CrystalReport1();
//Call all report modification code here.
//For illustration purposes, I'm calling a generice method that changes the report title.
//The code for ModifyTitle() isn't shown here.
ModifyTitle(MyReport, "Runtime Demo");
Session["MyReport"] = MyReport;
} else {
MyReport = (CrystalDecisions.CrystalReports.Engine.ReportDocument)Session["MyReport"];
}
CrystalReportViewer1.ReportSource = MyReport;
}
Listing 14-3. Forcing garbage collection in an ASP.NET page.
private void WebForm1_Init(object sender, System.EventArgs e)
{
if (MyReport!=null) {
MyReport.Close();
MyReport.Dispose();
GC.Collect();
}
}
Listing 14-4. Change a report’s printer settings.
CrystalReport1 MyReport = new CrystalReport1();
MyReport.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
MyReport.PrintOptions.PrinterName = "HP LasterJet510";
MyReport.PrintToPrinter(1, false, 0, 0);