devxlogo

Deploying the CrystalReportViewer Control to a Production Web Site

Deploying the CrystalReportViewer Control to a Production Web Site

All this information is available in pieces in various places, but perhaps gathering it all together will simplify the process. The following may not be the most elegant solution, but it works.

Assumption: You want to run an external Crystal XI report from your production web site. To do that, you’ve decided to use an ASPX Web Form containing a CrystalReportViewer control.

You’ll find that it’s easier to make that decision than to deploy the control to make it work in production; however, following this procedure should solve the problem:

  1. Copy the Crystal DLLs from your development machine into the bin directory on your web site. You’ll need these DLLs:
    • CrystalDecisions.CrystalReports.Engine.dll
    • CrystalDecisions.ReportSource.dll
    • CrystalDecisions.Shared.dll
    • CrystalDecisions.Web.dll

    You’ll find all these DLLs in C:Program FilesBusiness ObjectsCommon2.8managed on your Visual Studio 2008 development machine.

  2. Assuming that report accesses a stored procedure on a remote database, on the production machine, create an ODBC connection that matches the one you have on your development machine that the Crystal Report uses.

  3. Copy the report to the bin directory on the production machine.

The code in this example contains a hardcoded path string to the report. You’ll need to change that for your environment. The report has one parameter that is automatically filled from a session variable. The CrystalReportViewer (CRV) control (crv1) toolbar properties are all shown. I found that the CRV toolbar icons did not display or behave correctly, so I turned the bar off. I had no need for them. You’ll need to do some further exploration if you want to use them.

The following code shows how to call and display the report. I’ve included a Web.config file at the end of the code to show the required configuration.

using CrystalDecisions.Web;using Parameter=CrystalDecisions.Web.Parameter;using ParameterCollection=CrystalDecisions.Web.ParameterCollection;// CHANGE THISprivate const string SReport = "C:\Inetpub\wwwroot\myWebSite\bin\MyReport.rpt";protected void Page_Load(object sender, EventArgs e){   if (!Page.IsPostBack)      LoadReport(SReport);}private void LoadReport(string reportPath){   try   {      string sMeter = Session["PassedParameter"].ToString();      CrystalReportSource rs = new CrystalReportSource();                      Report rpt = new Report();      rpt.FileName = reportPath;      rs.Report = rpt;      rs.ReportDocument.SetDatabaseLogon("myuser","mypassword");      ParameterCollection pc = rpt.Parameters;      Parameter p = new Parameter();      p.DefaultValue = sMeter;      p.Name = "@myParam";// Same as in the report      pc.Add(p);      crv1.ReportSource = rs;      crv1.HasToggleGroupTreeButton = false;      crv1.HasExportButton = false;      crv1.HasPrintButton = false;      crv1.HasViewList = false;      crv1.HasDrillUpButton = false;      crv1.HasPageNavigationButtons = false;      crv1.HasGotoPageButton = false;      crv1.HasSearchButton = false;      crv1.HasZoomFactorList = false;      crv1.HasCrystalLogo = false;      crv1.DisplayToolbar = false;      crv1.DisplayGroupTree = false;      crv1.DisplayPage = true;      crv1.SeparatePages = false;   }   catch (Exception ex)   {      lblMessage.Text = "Load report error. " + ex.Message;   } }***WEB CONFIG FILE FOLLOWS***                                                                                                                                           

Perhaps someone can build on this beginning and publish a comprehensive article on this topic.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist