Skip to main content

XtraReport.FromFile(String, Boolean) Method

Loads the report definition from the specified REPX file.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v23.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public static XtraReport FromFile(
    string path,
    bool loadState = true
)

Parameters

Name Type Description
path String

A String value, specifying the full path (including the file name and extension) to the REPX or XML file.

Optional Parameters

Name Type Default Description
loadState Boolean True

true to restore the property values of a report along with the settings applied to its elements (bands and controls); false to load only the base type settings of the specified report.

Returns

Type Description
XtraReport

An XtraReport class (or its descendant, the type of which is specified in the REPX or XML file).

Remarks

Use the FromFile method to restore a report from its definition file (stored in the standard REPX, or a custom XML format).

Note

Deserialization of reports received from untrusted parties can trigger the execution of malicious code, which can either be directly embedded in the report definition or contained in an external assembly referenced by the report.

To avoid this, we recommend that you use XML serialization instead of CodeDOM (so that reports can be safely deserialized using the XtraReport.LoadLayoutFromXml method instead of the less secure LoadLayout method) and prevent any untrusted third-party libraries from being available on the server.

The CodeDOM serialization is not supported under the Full Trust permission level, and XML serialization is the only option to save reports.

To restore the report class settings, this method must locate the associated report type based on which specified report definition file was created. This type is searched for in the following assemblies:

  1. In the assembly (an EXE or DLL file) that produced the report definition file. Its path is also mentioned in the definition file’s header.
  2. In the current assembly (from which the FromFile method is called).
  3. In the assemblies referenced by the current assembly.
  4. In the loaded assemblies.

When this method fails to locate the originating class type, it creates a new XtraReport class instance.

Calling this method with its loadState parameter set to true will restore all custom property values of both a report and its elements.

Note

You can set the loadState parameter to true in most scenarios because the report specified in the definition file can be of the XtraReport type (for example, when a report was saved using the Visual Studio report designer). In this case, the false value in the loadState parameter causes the application to generate an empty report.

Example

This example demonstrates how to restore a report definition from a file by using the XtraReport.FromFile method.

In the following code, this method is called with its loadState parameter set to true, restoring all custom property values of both a report and its elements.

To run the following code, the application must successfully locate the assembly based on which the specified XtraReport1.repx file was created (either in the original project folder, among the assemblies referenced by the example, or in the GAC).

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
// ...

private void Form1_Load(object sender, EventArgs e) {
    // Restore a report from a file.
    XtraReport report = XtraReport.FromFile(@"..\\..\\XtraReport1.repx", true);

    // Show the report's Print Preview.
    ReportPrintTool printTool = new ReportPrintTool(report);
    printTool.ShowPreviewDialog();
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FromFile(String, Boolean) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also