1670041 - How to persist Crystal Reports using Cache in a custom .NET web application?

SAP Knowledge Base Article - Public

1670041 - How to persist Crystal Reports using Cache in a custom .NET web application?

Symptom

How to persist Crystal Reports using Cache in a custom .NET web application?

Environment

  • Crystal Reports 2008
  • Crystal Reports for Visual Studio 2010
  • Web Application using C#

Resolution

Use following code:

string cachedReports;
if (Session["ReportsName"] == null)
{
	string reportName = System.Guid.NewGuid().ToString();
	Session.Add("ReportsName", reportName);
	cachedReports = Session["ReportsName"].ToString();
}
else
{
	cachedReports = Session["ReportsName"].ToString();
}
if (Cache[cachedReports] == null)
{
	ReportDocument rd = new ReportDocument();
	rd.Load(Server.MapPath("Employee Sales.rpt"));
	Cache.Insert(cachedReports, rd, null, DateTime.MaxValue, TimeSpan.FromMinutes(10));
	CrystalReportViewer1.ReportSource = rd;
}
else
{
	CrystalReportViewer1.ReportSource = Cache[cachedReports];
}

Keywords

.net sdk maintain state cr4vs2010 crvs2010 crvs cr net 2008 , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports, developer version for Microsoft Visual Studio