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:
- 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 Files\Business Objects\Common\2.8\managed\ on your Visual Studio 2008 development machine.
- 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.
- 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 THIS
private 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***
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="CrystalDecisions.Web, Version=10.5.3700.0,
Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.Shared, Version=10.5.3700.0,
Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=10.5.3700.0,
Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0,
Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=10.5.3700.0,
Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Enterprise.Framework, Version=10.5.3700.0,
Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Enterprise.InfoStore, Version=10.5.3700.0,
Culture=neutral,
PublicKeyToken=692fbea5521e1304"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="None"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<httpHandlers><add verb="GET" path="CrystalImageHandler.aspx"
type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web,
Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers><add name="CrystalImageHandler.aspx_GET" verb="GET"
path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler,
CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral,
PublicKeyToken=692fbea5521e1304"
preCondition="integratedMode"/></handlers>
</system.webServer>
</configuration>
Perhaps someone can build on this beginning and publish a comprehensive article on this topic.