Progress® Telerik® Reporting R3 2021

New to Telerik Reporting? Download free 30-day trial

Serialize Report Definition in XML

Telerik Reporting supports serialization/deserialization of the report definition as plain XML. This is useful in various different scenarios and opens many possibilities that are not easily accomplished otherwise. For example, this allows adding or modifying reports in your application without recompiling or redeploying it. Another typical scenario is saving/loading of dynamically generated report definitions or transferring them over the network.

In order to better handle report definition resources we also provide a ReportPackager that serializes the report definition in XML and packages it together with its resources in a file with zip compression. For more information see: Package Report Definition.

Class Report Definition

The XML serialization/deserialization of report definitions is achieved through the dedicated ReportXmlSerializer class. To illustrate how a report is serialized and deserialized, let us start with a simple dynamically generated class report definition:

var report = new Report1();

report.Width = Telerik.Reporting.Drawing.Unit.Inch(4);

var detailSection = new Telerik.Reporting.DetailSection();

detailSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2);

var numberTextBox = new Telerik.Reporting.TextBox();

numberTextBox.Value = "=Fields.ProductNumber";
numberTextBox.Left = Telerik.Reporting.Drawing.Unit.Inch(0);
numberTextBox.Top = Telerik.Reporting.Drawing.Unit.Inch(0);
numberTextBox.Width = Telerik.Reporting.Drawing.Unit.Inch(2);
numberTextBox.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2);

var nameTextBox = new Telerik.Reporting.TextBox();

nameTextBox.Value = "=Fields.Name";
nameTextBox.Left = Telerik.Reporting.Drawing.Unit.Inch(2);
nameTextBox.Top = Telerik.Reporting.Drawing.Unit.Inch(0);
nameTextBox.Width = Telerik.Reporting.Drawing.Unit.Inch(2);
nameTextBox.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2);

var dataSource = new Telerik.Reporting.SqlDataSource();

dataSource.ConnectionString = "Data Source=.\\SqlExpress;Initial Catalog=AdventureWorks;Integrated Security=True";
dataSource.SelectCommand = "select ProductNumber, Name from Production.Product";
report.DataSource = dataSource;

Serialize to XML

The following sample code snipped demonstrates how to serialize the above report definition to an XML file:

using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create("SerializedReport.xml"))
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    xmlSerializer.Serialize(xmlWriter, report);

Deserialize from XML

The corresponding code that can be used to deserialize the report definition from the file is shown below:

System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
settings.IgnoreWhitespace = true;

using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create("Report1.xml", settings))
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    Telerik.Reporting.Report report = (Telerik.Reporting.Report)

XML Report Definition

and the resulting XML file would look like this:

<Report DataSourceName="sqlDataSource1" Width="4in" Name="userReport1" xmlns="">
    <SqlDataSource ConnectionString="Data Source=.\SqlExpress;Initial Catalog=AdventureWorks;Integrated Security=True" SelectCommand="select ProductNumber, Name from Production.Product" Name="sqlDataSource1" />
    <DetailSection Height="0.2in" Name="detailSection1">
        <TextBox Value="=Fields.ProductNumber" Size="2in, 0.2in" Location="0in, 0cm" Name="textBox1" />
        <TextBox Value="=Fields.Name" Size="2in, 0.2in" Location="2in, 0cm" Name="textBox2" />
    <PageSettings PaperKind="Letter" Landscape="False">
        <MarginsU Left="1in" Right="1in" Top="1in" Bottom="1in" />
In this article
Not finding the help you need?