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:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may