Hello Pat,
Sorry, it seems that I didn't correctly describe the way this feature is implemented in v2007 vol 3. As I said before, the ReportViewer class introduces the CacheReportDocument and RestoreReportDocumentFromCache events. The CacheReportDocument event occurs after a report document (XtraReport.PrintingSystem.Document) is generated for the first time. And this event allows you to save a document as a collection of Page objects within their bricks (so, a datasource is no longer necessary) into any place you want. For example:
protected void ReportViewer1_CacheReportDocument(object sender, CacheReportDocumentEventArgs e) {
e.Key = Guid.NewGuid().ToString();
Page.Session[e.Key] = e.SaveDocumentToMemoryStream();
}
And then you may restore a document using the RestoreReportDocumentFromCache event, which occurs every time a ReportViewer requires a document (e.g. when an end-user navigates to a different document page):
protected void ReportViewer1_RestoreReportDocumentFromCache(object sender, RestoreReportDocumentFromCacheEventArgs e) {
Stream stream = Page.Session[e.Key] as Stream;
if(stream != null)
e.RestoreDocumentFromStream(stream);
}
Note that you aren't obliged to save a document to a page's session or cache - you may use any other destination to save a report's document. For example, this code snippet demonstrates how to implement a more complex caching approach to save all documents to a temporary folder on a disk:
protected void ReportViewer1_CacheReportDocument(object sender, CacheReportDocumentEventArgs e) {
if(CanCreateFile())
e.SaveDocumentToFile(FullFileName);
}
protected void ReportViewer1_RestoreReportDocumentFromCache(object sender, RestoreReportDocumentFromCacheEventArgs e) {
if(CanReadFile())
e.RestoreDocumentFromFile(FullFileName);
foreach(string fileName in Directory.GetFiles(Helper.GetRelativePath(string.Empty), FileNamePrefix + "*.prnx")) {
try {
string[] dateParts = Path.GetFileNameWithoutExtension(fileName).Replace(FileNamePrefix, string.Empty).Split('_');
DateTime date = new DateTime(int.Parse(dateParts[0]), int.Parse(dateParts[1]), int.Parse(dateParts[2]));
if(date != DateTime.Today)
File.Delete(fileName);
} catch {
}
}
}
bool CanCreateFile() {
try {
using(File.Open(FullFileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)) { }
} catch {
return false;
}
return true;
}
bool CanReadFile() {
try {
using(File.Open(FullFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { }
} catch {
return false;
}
return true;
}
Of course, these examples are not full, and don't allow you to test them without v2007 vol 3. Please wait until it's officially released, and you'll be ready to implement report caching in the most suitable way.
@.
R&D, .NET Team.
PS. If you wish to receive direct assistance from our Support Team, use Support Center at http://www.devexpress.com/sc.