Skip to main content
A newer version of this page is available. .

Save and Open Report Documents

  • 4 minutes to read

This document provides code examples on how to use the PrintingSystemBase.SaveDocument and PrintingSystemBase.LoadDocument methods for saving and loading report documents.

Tip

Consider the following when using different overloads of the XtraReport.CreateDocument method:

  • When using this method’s default overload without parameters, you cannot interrupt or cancel the document creation process. Once the document creation has started, it runs until the resulting document is complete.
  • Call this method’s overload with the buildForInstantPreview parameter set to true to access document pages progressively as they are created, as well as interrupt or cancel document creation.

Saving Documents to a File

The following examples illustrate how to save a report document to a file and then load it in Print Preview:

  • Saving documents to a file:

    // The path to a report document's file.
    string filePath = @"C:\Temp\Report1.prnx";
    
    private void button1_Click(object sender, System.EventArgs e) {
        // Create a report instance. 
        XtraReport1 report = new XtraReport1();
    
        // Generate a complete report document.
        report.CreateDocument();
    
        // Save the document to a file. 
        report.PrintingSystem.SaveDocument(filePath);
    }
    
  • Loading documents from a file:

    using DevExpress.XtraReports.UI;
    // ...
    
    // The path to a report document's file. 
    string filePath = @"C:\Temp\Report1.prnx";
    
    private void button1_Click(object sender, System.EventArgs e) {
        // Create a Print Tool with an assigned report instance.
        ReportPrintTool printTool = new ReportPrintTool(new XtraReport1());
    
        // Access the Print Tool's Printing System and load the report document.
        if (System.IO.File.Exists(filePath)) {
            printTool.PrintingSystem.LoadDocument(filePath);
        }
        else {
            System.Console.WriteLine("The source file does not exist.");
        }
    
        // Load a Print Preview in a dialog window.
        // printTool.ShowPreviewDialog()
        printTool.ShowRibbonPreviewDialog();
    }
    

Saving Documents to a Stream

The following examples illustrate how to save a report document to a stream and then load it in Print Preview:

  • Saving documents to a stream:

    // Create a Memory Stream instance.
    System.IO.MemoryStream stream = new System.IO.MemoryStream();
    
    private void button1_Click(object sender, System.EventArgs e) {
        // Create a report instance. 
        XtraReport1 report = new XtraReport1();
    
        // Generate a complete report document.
        report.CreateDocument();
    
        // Save the document to a stream. 
        report.PrintingSystem.SaveDocument(stream);
    }
    
  • Loading documents from a stream:

    using DevExpress.XtraReports.UI;
    // ...
    
    // Create a Memory Stream instance.
    System.IO.MemoryStream stream = new System.IO.MemoryStream();
    
    private void button1_Click(object sender, System.EventArgs e) {
        // Create a Print Tool with an assigned report instance.
        ReportPrintTool printTool = new ReportPrintTool(new XtraReport1());
    
        // Access the Print Tool's Printing System and load the report document.
        printTool.PrintingSystem.LoadDocument(stream);
    
        // Load a Print Preview in a dialog window.
        // printTool.ShowPreviewDialog();
        printTool.ShowRibbonPreviewDialog();
    }