Creating a DotNetNuke Private Assembly with Crystal Reports - Part 4
Published: 16 Jan 2006
Unedited - Community Contributed
This is the final part in a series about creating a quick way to manage Crystal Reports in a DotNetNuke private assembly.
by Eric Landes
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 20331/ 37


As mentioned in Part 1 of this series, DotNetNuke is a great Open Source Portal tool that many in the ASP.NET world use.  Please refer to Part 1 for more information about DotNetNuke(DNN).  In Part 2, we explored the DNN Data Access architecture for our application, and we created our own DAL and BLL based on the DNN architecture.  In Part 3, we utilized a helper class to dynamically display reports parameters for user input.   

In Part 4, we take those dynamically created parameter entries and display the report using those parameter entries in the report viewer module.    In this way, we’ve created a basic Report Manager for Crystal Reports using the DNN framework.  This basic manager could also be a gateway to integration with Crystal Enterprise Manager. 

System Requirements

I created this project using Visual Studio 2003, DotNetNuke 3.1.1, SQL Server 2000, and Crystal Reports 10, Windows XP SP2.

Controls Used in the Module

Download Source

To refresh your memory, remember that in Part 3 we are displaying the parameters in a Panel container on the ReportViewer.ascx user control page.  A button that is hidden on the page is visible once the parameters are populated.  Clicking on this button displays the report, and is the subject of this article.

The controls that are not dynamically created on the page include a Crystal Viewer control (crvShowReport).  This control’s Visible is set to false initially.  Once we have applied the parameters, we will bind the report to that control and make it visible.  Another option for intranets might be to use the ExportToPdf function in the sample to send the report immediately to PDF in the browser rather than using the Crystal viewer.  This is especially useful if you have versions of Crystal on your server prior to version 10.  If you do have Version 10 or later, and have installed that on your server, the viewer has exporting to PDF features built in.  In this article, we are going to utilize the Crystal Viewer.

Displaying the Report

Let’s get to how to display our report.  Assuming that we have entered valid data in the parameter entries displaying in the panel, we need to press the now visible “View Report” button.  That button runs the code to set the login parameters, bind the report to a Crystal Report Document, and then bind that document to the Crystal Viewer on the page.     

Once the button is clicked, the btnViewReport_Click event fires.  We instantiate a new CRDisplayReport object and then set the reportname, dbname, servername, userid, and password property.  Then we call the method CreateReportToView, which returns a ReportDocument object that we bind to the Crystal Report Viewer.  See Code Listing 1 for the code.

Code Listing 1

CRDisplayReport oDisplay = new CRDisplayReport();
// This is where we put the selected reportname
and dbname etc.  For the article this is hardcoded.
oCRDoc = oDisplay.CreateReportToView(Request);

You can see from this code that the Crystal Report Viewer is bound to OCRDoc object.  This object is created from the CreateReportToView method.  The code for this method is found in Code Listing 2.

Code Listing 2

oReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); 
oDiscreteParam = new CrystalDecisions.Shared.ParameterDiscreteValue(); 
oDefaultValues = new CrystalDecisions.Shared.ParameterValues(); 
  int iCurrParm = 1;
(CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition oCRParam in oReport.DataDefinition.ParameterFields)

    oDiscreteParam.Value =
GetRequest(oCRParam.ParameterFieldName + iCurrParm.ToString(), oCRParam,

  return oReport;
catch (Exception e) 
  throw new
Exception("CRDisplayReport.CreateReportView experienced an error: " +

This code, also modified from a previous article, creates a Reportdocument oReport.  We load the report using the _reportname property.  iCurrParm follows the convention used previously that makes sure that all parameter names are unique.  This is how you can find the parameter names created in Part 3 of this series. 

We iterate through the all the parameters in the report using a foreach loop.  The value applied to each parameter (this assumes a DiscreteParamValue), is applied via the GetRequest method. 

The GetRequest method takes the parameter name, the parameter object, and the request object to find the appropriate parameters.  Because we need to find the controls via the request rather than the page.findcontrol method, we iterate through all the parameters in the request to find the correct parameter passed.

Once that parameter is found through the request object, it gets passed back to oDiscreteParam.Value.  After the parameters get applied, we need to pass the login information to the Report document.  This is done through the ApplyLoginInfo method shown in Code Listing 3.

Code Listing 3

oCRDb  = _oRpt.Database;
oCRTables = oCRDb.Tables;
oCRConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
oCRConnectionInfo.DatabaseName = _dbName;
oCRConnectionInfo.ServerName = _serverName;
oCRConnectionInfo.UserID = _userID;
oCRConnectionInfo.Password = _passWord;
oCRTable in oCRTables)
  oCRTableLogonInfo = oCRTable.LogOnInfo;
  oCRTableLogonInfo.ConnectionInfo =

This code simply applies the login information to the report document.  Once that’s done, the report object is returned back to the calling program.  In this case, that’s the User Control ReportsViewer btnViewReport_Click  event.  Once the object is bound to the viewer, the CrystalViewer objects Visible property is set to true.  Now the report is visible on the page!


We’ve gone from creating the DAL and BLL for our DNN module.  Then, we loaded the report and dynamically displayed the report’s parameters.  Finally, we take those parameter entries and apply them to the reporting document.

That’s the module for DNN.  I had thought that folks might want to continue this as an open source project.  If someone wants to continue tuning this, I will set up something on GotDotNet Workspaces or Sourceforge.  Just drop me a line using the contact button.  Until then, Happy Coding!

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2021  |  Page Processed at 2021-03-01 5:37:04 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search