Skip to main content

CachedReportSource.CreateDocumentAsync() Method

Creates a document from the report specified by the CachedReportSourceBase.Report property, so it can be displayed, printed and exported. Runs document generation in an individual task asynchronously.

Namespace: DevExpress.XtraPrinting.Caching

Assembly: DevExpress.Printing.v24.1.Core.dll

NuGet Package: DevExpress.Printing.Core

Declaration

public override Task CreateDocumentAsync()

Returns

Type Description
Task

The task where document generation is performed.

Remarks

To display a report, a Print Preview (Document Viewer) generates a report document internally. However, you may need to obtain a report document without viewing it in a Print Preview, for instance, to merge reports, export or print them in code. In this instance, use the CreateDocumentAsync method to generate a report document manually.

using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...
private void button_Click(object sender, EventArgs e) {
    var storage = new MemoryDocumentStorage();
    var report = new MyReport();
    var cachedReportSource = new CachedReportSource(report, storage);
    cachedReportSource.CreateDocumentAsync();
}

This method returns the Task object, since the method performs document generation asynchronously. Use the Task object’s members to learn about the current document generation status. For instance, use the Wait() method to wait for the task’s completion before starting another document generation task. Simultaneous document generation raises the InvalidOperationException exception.

To restart a document generation, call the CachedReportSourceBase.StopPageBuilding method and wait until the task where this method operates completes. Then, call the CreateDocumentAsync method again.

You can access the generated document using the members of the object provided by the PrintingSystemBase.Document property of the CachedReportSource‘s CachedReportSourceBase.PrintingSystem.

If a report contains parameters and the XtraReport.RequestParameters property is set to true, reference the DevExpress.XtraPrinting.v24.1.dll assembly in your project and assign a ReportPrintTool to the report before calling the CreateDocumentAsync method.

using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...
private void button1_Click(object sender, EventArgs e) {
    var storage = new MemoryDocumentStorage(); 
    var report = new MyReport(); 
    ReportPrintTool tool = new ReportPrintTool(report);
    var cachedReportSource = new CachedReportSource(report, storage); 
    cachedReportSource.CreateDocument();
}

The code above invokes the dialog requesting the report parameters’ values and then generates a document according to the specified parameter values.

ReportParameters3

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CreateDocumentAsync() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also