Back to Devexpress

Manage Report Documents in Code

xtrareports-4811-feature-guide-to-devexpress-reports-store-and-distribute-reports-store-report-layouts-and-documents-save-and-open-report-documents.md

latest6.6 KB
Original Source

Manage Report Documents in Code

  • Feb 18, 2026
  • 4 minutes to read

Reporting for WinForms

Code snippets in this section show how to use the report’s SaveDocument and LoadDocument methods to save and load report documents.

Save a Document to a File

csharp
// Specify the path to a report document file.
string filePath = @"C:\Temp\Report1.prnx";

// Create a report instance. 
XtraReport1 report = new XtraReport1();

// Create a report document.
report.CreateDocument();

// Save the created report document to a file. 
report.PrintingSystem.SaveDocument(filePath);
vb
' Specify the path to a report document file.
Private filePath As String = "C:\Temp\Report1.prnx"

' Create a report instance. 
Dim report As New XtraReport1()

' Create a report document.
report.CreateDocument()

' Save the created report document to a file. 
report.PrintingSystem.SaveDocument(filePath)

Load a Document from a File

csharp
using DevExpress.XtraReports.UI;
// ...

// Specify the path to a report document file. 
string documentPath = @"C:\Temp\Report1.prnx";

// Specify the file to which the report document should be exported.
string exportPath = @"C:\Temp\Report1.docx";

// Create a new report instance.
XtraReport report = new XtraReport();

// Load the report document.
if (System.IO.File.Exists(documentPath)) {
    report.PrintingSystem.LoadDocument(documentPath);
}
else {
    System.Console.WriteLine("The source file does not exist.");
}

// Export the loaded report document to DOCX format.
report.ExportToDocx(exportPath);
vb
Imports DevExpress.XtraReports.UI
' ...

' Specify the path to a report document file.
Private documentPath As String = "C:\Temp\Report1.prnx"

' Specify the file to which the report document should be exported.
Private exportPath As String = "C:\Temp\Report1.docx"

' Create a new report instance.
Private report As New XtraReport()

' Load the report document.
If System.IO.File.Exists(documentPath) Then
    report.PrintingSystem.LoadDocument(documentPath)
Else
    System.Console.WriteLine("The source file does not exist.")
End If

' Export the loaded report document to DOCX format.
report.ExportToDocx(exportPath)

Save a Document to a Stream

csharp
// Create a Memory Stream.
using (MemoryStream stream = new MemoryStream()) {

    // Create a report instance. 
    XtraReport1 report = new XtraReport1();

    // Create a report document.
    report.CreateDocument();

    // Save the created report document to the stream. 
    report.PrintingSystem.SaveDocument(stream);
}
vb
' Create a Memory Stream.
Using stream As MemoryStream = New MemoryStream()

    ' Create a report instance. 
    Dim report As XtraReport1 = New XtraReport1()

    ' Create a report document.
    report.CreateDocument()

    ' Save the created report document to the stream.
    report.PrintingSystem.SaveDocument(stream)
End Using

Load a Document from a Stream

csharp
using DevExpress.XtraReports.UI;
// ...

// Declare a data byte array that should store the document.
byte[] reportBytes;

// Create a report instance. 
XtraReport report = new XtraReport();

// Create a Memory Stream.
using (MemoryStream stream = new MemoryStream(reportBytes)) {

    // Load the report document.
    report.PrintingSystem.LoadDocument(stream);
}

// Send the loaded report document to the specified printer.
report.Print("PrinterName");
vb
Imports DevExpress.XtraReports.UI
' ...

' Declare a data byte array that should store the document.
Dim reportBytes As Byte()

' Create a new report instance.
Dim report As XtraReport = New XtraReport()

' Create a Memory Stream.
Using stream As MemoryStream = New MemoryStream(reportBytes)

    ' Load the report document.
    report.PrintingSystem.LoadDocument(stream)
End Using

' Send the loaded report document to the specified printer.
report.Print("PrinterName")

Reporting for WPF

Add the DocumentViewerControl component to your project. Assign a document source to the DocumentSource property.

The following types of document sources are supported:

  • An object that implements the IReport interface.
  • An object that implements the ILink interface.
  • A Stream that contains report document data.
  • A string that contains a path to a file that stores report document data (a PRNX file).

If you use the IReport or ILink object as a document source, call the document source’s CreateDocument method or set the DocumentPreviewControl’s RequestDocumentCreation property to True to generate a preview.

xaml
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing" Loaded="Window_Loaded">
    <Grid>
        <dxp:DocumentPreviewControl x:Name="documentPreview" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
    </Grid>
</Window>
csharp
// ...
private void Window_Loaded(object sender, RoutedEventArgs e) {
    documentPreview.DocumentSource = "CustomerOrder.prnx";
}
// ...
vb
' ...
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    documentPreview.DocumentSource = "CustomerOrder.prnx"
End Sub 
' ...