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.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as