In this blog post, Haissam Abdul Malak will explain how to dynamically load a crystal report file into a webform by using the CrystalReportViewer class and how to successfully deploy the application
. For instance, suppose you have ".rpt" file in your web application folder and you dynamically want to show it in the page. Below is the code to use
// Get the filePath
string filePath = Server.MapPath("~/Reports/report1.rpt");
// Create new instance of the CrystalReportViewerClass
CrystalReportViewer rptViewer = new CrystalDecisions.Web.CrystalReportViewer();
// Create new instance of the Report Document
ReportDocument rptDoc = new ReportDocument();
// Load the rpt file into the ReportDocument Class
rptDoc.Load(filepath);
// Set the already loaded rpt file into the CrystalReportViewer class
rptViewer.ReportSource = rptDoc;
// Add the control to the page
Page.Form.Controls.Add(rptViewer);
P.S: You should add CrystalDecisions.CrystalReports.Engine and CrystalDecisions.Web and import them.
Now locally it should work because when installing VS 2005, it will install to your local pc all the dlls needed for the crystal report rendering in the GAC . However, you might encounter problems when deploying the application on a web server where the dlls are not installed. One of the solutions is to install the dlls on the web server. You can locate the installer on your local pc at "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\CrystalReports". The file name is "CRRedist2005_x86.msi". Run this installer on your webserver
and re-run the application.
Hope this helps,
No comments:
Post a Comment