1218912 - How to use the 'ICachedReport' interface in a .NET application

SAP Knowledge Base Article - Public

1218912 - How to use the 'ICachedReport' interface in a .NET application

Symptom

A Microsoft Visual Studio .NET web application uses the Crystal Reports 10 for .NET SDK as the reporting development tool. The application is designed to allow many users to view reports.

How can you use the 'ICachedReport' interface to allow multiple users to view a small number of reports with the same data?

Resolution

The following code is an example of a C# class that implements the 'ICachedReport' interface:

----------------------------------------

using System;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using System.ComponentModel;
 
namespace MyCachedReports
{
/// <summary>
/// Summary description for CachedReport.
/// </summary>
public class CachedReport : Component, ICachedReport
{
// Declare variables
protected ReportDocument Report;
protected bool isCacheable;
protected bool shareDBLogonInfo;
protected string reportName;
protected TimeSpan cacheTimeOut;
 
public CachedReport(string s)
{
// Set the path to the report.
this.reportName = s;
this.Report = new ReportDocument();
}
 
// Declare properties defined in the ICachedReport interface.
 
// Get or set a value indicating whether or
// not the report is cacheable.
public virtual Boolean IsCacheable
{
get
{
return isCacheable;
}
set
{
isCacheable = value;
}
}
 
// Get or set a value indicating whether or not the
// report instances will differentiate between
// different database logons.
public virtual Boolean ShareDBLogonInfo
{
get
{
return shareDBLogonInfo;
}
set
{
shareDBLogonInfo = value;
}
}
 
// Get or set a value indicating the amount of
// time for the report to remain in the ASP.NET cache.
public virtual TimeSpan CacheTimeOut
{
get
{
return cacheTimeOut;
}
set
{
cacheTimeOut = value;
}
}
 
// Declare methods defined in the ICachedReport interface.
 
// Create and return an instance of the report.
public virtual ReportDocument CreateReport()
{
Report.Load(reportName);
return Report;
}
 
public ReportDocument GetReport(RequestContext request)
{
return this.Report;
}
 
// Create and return a customized cache key.
public virtual String GetCustomizedCacheKey
(RequestContext request)
{
String key = null;
// The following is the code used to generate the default
// cache key for caching report jobs in the ASP.NET Cache.
// Feel free to modify this code to suit your needs.
// Returning key == null causes the default cache key to
// be generated.
 
key = RequestContext.BuildReportFileNameKey(
reportName);
return key;
}
}
}

 

----------------------------------------

 

The following sample code opens a report with the above custom class and sets its properties:

 

----------------------------------------

CachedReport report = new CachedReport("C:\\myReport.rpt");
report.IsCacheable = true;
report.ShareDBLogonInfo = true;
report.CacheTimeOut = System.TimeSpan.FromMinutes(10);

 

See Also

For more information on using the 'ICachedReport' interface, please refer to Note 1218482

Keywords

DOT NET DOTNET ICACHEDREPORT CSHARP C SHARP # CACHEING SHARING SHARED c2017422 Crystal Reports for Visual Studio ICachedReport interface How to use , c2017682 , KBA , BI-RA-CR , Crystal Reports designer or BusinessViews Manager , How To

Product

SAP Crystal Reports 10.0