Crystal Reports Extension Methods Library

After using Crystal Reports for many years what always strikes me is that some of the methods available via API are not generic enough and require unnecessary repeated coding for simple things.

Lately all my development, when in comes to reports, is based on Crystal Reports 2008  engine within ASP.Net/C# environment. While there are many improvements in the functionality available to developers, there are still things which could be done easier. So what do we do to make our job easier? We develop set of special classes, wrappers and libraries which would simplify work with Crystal Reports API.

But disadvantage of introducing yet another helper class, is that it is another helper class. We are loosing simple inheritance of the new functionality in API and make code even more complex.
But there is a nice feature in .Net which helps avoid problem above – Extension Methods – it allows attach additional functionalities to an existing type/class even if you do not have access to the source for it.

Idea is then to keep using Crystal Report’s ReportDocument class and build on top of it by providing extra methods that can be useful when you want to integrate Crystal Reports in your .Net application.

Note #1. If you have ideas or suggestions for new methods, please let me know.
Note #2.This is work in progress and new versions would be available in the future. You can always download the latest version here.
Note #3. Library is developed and tested for Visual Studio 2008 and Crystal Reports 2008 with SP1.
Note #4. Code is self-documented using XMLDoc.

In order to introduce new methods into your code, simply compile a provided assembly and add reference in your code. After that you should see new methods listed below available for each ReportDocument instance.

Currently included:

// Assign the connection info to all tables in the report
public static void AssignTableConnections(this ReportDocument reportDocument, ConnectionInfo  connectionInfo)
// Close opened report, otherwise throw exception
public static void CloseReport(this ReportDocument reportDocument)
// Export report into file of specified format
public static void Export(this ReportDocument reportDocument, string fileName,  CrystalDecisions.Shared.ExportFormatType exportFormatType)
// Checks if specified parameter is present in the report
public static bool HasReportParameter(this ReportDocument reportDocument, string paramName)
// Function returns list of parameters descriptions with associated
// values for specified report instance in the form of HTML code block
//  which then can be used in the report to display current parameter
public static string GetReportParamsAsText(this ReportDocument reportDocument)
// Set specified report parameter
public static void SetReportParameter(this ReportDocument reportDocument, string paramName, object paramValue)
// Load report and prepare database connection using provided Server, Database Names, and login info
public static void OpenReport(this ReportDocument reportDocument, string reportFile,  ConnectionInfoType type, string serverName, string databaseName,  bool integratedSecurity, string userName, string password)
public static void OpenReport(this ReportDocument reportDocument, string reportFile, ConnectionInfoType type, string serverName, string databaseName, string userName, string password)
public static void OpenReport(this ReportDocument reportDocument, string reportFile, ConnectionInfoType type, string serverName, string databaseName)
// Purge saved report data if present
public static void PurgeSavedData(this ReportDocument reportDocument)
This entry was posted in Crystal Reports, Technology and tagged , , , , , , . Bookmark the permalink.

Leave a Reply