Back to Devexpress

XtraReport.FromXmlStream(Stream, Boolean) Method

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-dot-fromxmlstream-x28-system-dot-io-dot-stream-system-dot-boolean-x29.md

latest5.7 KB
Original Source

XtraReport.FromXmlStream(Stream, Boolean) Method

Loads the report definition data from the specified stream and creates a report object from it. The created report’s class is also specified in the XML data format.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public static XtraReport FromXmlStream(
    Stream stream,
    bool loadState = true
)
vb
Public Shared Function FromXmlStream(
    stream As Stream,
    loadState As Boolean = True
) As XtraReport

Parameters

NameTypeDescription
streamStream

The Stream object that contains the XML data to load.

|

Optional Parameters

NameTypeDefaultDescription
loadStateBooleanTrue

true , to load the report’s state which is also saved in the XML data; otherwise, false.

|

Returns

TypeDescription
XtraReport

An XtraReport class or its descendant of the type specified in the XML data.

|

Remarks

Use the FromXmlStream method to create a report instance from the report definition data stored in the specified stream. To create the report, this method should find the report’s class type. The class type name is stored in the XML data header. This type is searched for in the following assemblies:

  1. In the current assembly where the FromXmlStream method is called from;
  2. In the assemblies referenced by the current assembly;
  3. In the loaded assemblies.

If this class type is not found, an instance of the XtraReport class is created.

Set the loadState parameter to true to apply the saved state to the created report instance.

Example

This example demonstrates how to use the XtraReport.SaveLayoutToXml method to save a report definition to a stream (assigned to a corresponding Session object) as an XML file, and how to use the XtraReport.FromXmlStream method to restore the report definition.

csharp
using System.IO;
using DevExpress.XtraReports.UI;
// ...
private MemoryStream report_stream;
private void StoreReport(XtraReport report) {
    // Create a stream. 
    MemoryStream stream = new MemoryStream();

    // Save a report to the stream. 
    report.SaveLayoutToXml(stream);

    // Save the stream to a session. 
    this.report_stream = stream;
}

private XtraReport RestoreReport() {
    // Restore the stream from the session. 
    MemoryStream stream = (MemoryStream)this.report_stream;

    // Create a report from the stream. 
    return XtraReport.FromXmlStream(stream, true);
}
vb
Imports System.IO
Imports DevExpress.XtraReports.UI
' ...
Private report_stream As MemoryStream
Private Sub StoreReport(ByVal report As XtraReport)
    ' Create a stream. 
    Dim stream As New MemoryStream()

    ' Save a report to the stream. 
    report.SaveLayoutToXml(stream)

    ' Save the stream to a session. 
    Me.report_stream = stream
End Sub

Private Function RestoreReport() As XtraReport
    ' Restore the stream from the session. 
    Dim stream As MemoryStream = CType(Me.report_stream, MemoryStream)

    ' Create a report from the stream. 
    Return XtraReport.FromXmlStream(stream, True)
End Function

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FromXmlStream(Stream, 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.

reporting-asp-net-core-drill-through/CS/Services/CustomReportProviderAsync.cs#L27

csharp
ms.Position = 0;
    return XtraReport.FromXmlStream(ms);
}

See Also

XtraReport Class

XtraReport Members

DevExpress.XtraReports.UI Namespace