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

Load Report Layouts

  • 4 minutes to read

This document describes how to load report layouts in the Visual Studio or end-user Report Designers.

Tip

See Store Report Layouts for general information on storing reports.

Loading Reports using Application GUI

You can load a report definition in the Visual Studio Report Designer by clicking the report’s smart tag and selecting Open/Import in its actions list.

open-import-report-visual-studio-design-time

In addition to opening DevExpress reports, the Import Report dialog displayed in Visual Studio enables you to import reports produced by third-party vendors. This option is not available in end-user Report Designers.

import-dialog-visual-studio

Tip

Desktop (WinForms and WPF) end-user Report Designers provide Open buttons for loading reports.

The Web Report Designer provides this button after implementing and registering a report storage.

When applying a serialized layout to an existing report, you can update data bindings in the opened report and match them to the current report’s data sources.

Loading Reports in Code

You can use the following API to load reports and report style sheets in code:

Recommended API

Legacy API

XtraReport.LoadLayoutFromXml

Loads an XML containing a report’s layout from a file or stream.

XtraReport.LoadLayout

Loads a report’s layout from a CodeDOM object model contained in a file or stream.

XtraReport.FromFile and XtraReport.FromStream

These static methods create a new report instance and apply a new layout to it.

When creating a report using these static methods, your application must be able to locate and identify the report’s class type (its name is stored in the report definition’s header). This type is searched for in the following assemblies (in this order):

  1. The assembly (an EXE or DLL file) that produced the report definition (the report definition’s header specifies its path).
  2. The current assembly from which the corresponding static method was called.
  3. Other assemblies referenced by the current assembly.

These methods create a new XtraReport‘s instance if they fail to identify the class type, and load the specified report layout to it.

XRControlStyleSheet.LoadFromXml

Loads an XML containing a report’s style sheet from a file or stream.

XRControlStyleSheet.LoadFromFile and XRControlStyleSheet.LoadFromStream

Loads a report’s style sheet from a CodeDOM object model contained in a file or stream.

Important

We recommend using XML serialization to prevent unauthorized code injections into a report’s definition and execution of harmful code on a client machine when deserializing CodeDOM reports.

See Reporting Security for more information on security considerations related to storing and distributing DevExpress reports.

The following code illustrates the recommended approach to loading reports:

// A path to a report's definition file.
string reportFilePath = @"C:\Temp\Report1.repx";

// A path to a report style sheet.
string styleSheetFilePath = @"C:\Temp\ReportStyleSheet1.repss";

private void button1_Click(object sender, System.EventArgs e) {
    // Create a report instance.
    XtraReport1 report = new XtraReport1();

    // Load a report's layout from XML.
    if (System.IO.File.Exists(reportFilePath)) {
        report.LoadLayoutFromXml(reportFilePath);
    } 
    else {
        System.Console.WriteLine("The source file does not exist.");
    }

    // Load a report's style sheet from XML.
    if (System.IO.File.Exists(styleSheetFilePath)) {
        report.StyleSheet.LoadFromXml(styleSheetFilePath);
    } 
    else {
        System.Console.WriteLine("The source file does not exist.");
    }
}

Tip

See the following topics to learn about the supported serialization formats:

Ensure Safe Loading of Reports

The latest WinForms and WPF End-User Report Designers display a warning when attempting to load a potentially harmful report:

report-designer-load-report-warning

A report is considered harmful on finding any of the following content in it (or in any of its subreports):

Important

The contents listed above expose a client application to the risk of executing arbitrary code injected into a report’s definition when these reports are opened on the client.

See Reporting Security for more information on security considerations related to storing and distributing DevExpress reports.

See the following documents to find out how to prevent end-users from loading these reports (or enable loading them silently instead):

See Also