xtrareports-4811-feature-guide-to-devexpress-reports-store-and-distribute-reports-store-report-layouts-and-documents-save-and-open-report-documents.md
Code snippets in this section show how to use the report’s SaveDocument and LoadDocument methods to save and load report documents.
// 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);
' 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)
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);
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)
// 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);
}
' 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
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");
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")
Add the DocumentViewerControl component to your project. Assign a document source to the DocumentSource property.
The following types of document sources are supported:
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.
<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>
// ...
private void Window_Loaded(object sender, RoutedEventArgs e) {
documentPreview.DocumentSource = "CustomerOrder.prnx";
}
// ...
' ...
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
documentPreview.DocumentSource = "CustomerOrder.prnx"
End Sub
' ...