Save and Load Report Documents
- 3 minutes to read
The code snippets in this document illustrate how to use the report’s PrintingSystem.SaveDocument and PrintingSystem.LoadDocument methods to save and load report documents.
Save a Document to a File
// 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);
Load a Document from a File
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(filePath)) {
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);
Save a Document to a Stream
// 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);
}
Load a Document from a Stream
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");