Serializes and deserializes objects into and from XML.
This class is dedicated for serializing and deserializing objects
only from the
Telerik.Reporting namespace.
Namespace: Telerik.Reporting.XmlSerializationAssembly: Telerik.Reporting (in Telerik.Reporting.dll)
Syntax
| C# |
|---|
public class ReportXmlSerializer |
| Visual Basic |
|---|
Public Class ReportXmlSerializer |
Examples
The following example demonstrates how to create a report definition, how to serialize and deserialize it in XML and the corresponding XML output.
Creating the report definition:
CopyC#
Telerik.Reporting.Report report = new Telerik.Reporting.Report();
report.Width = Telerik.Reporting.Drawing.Unit.Inch(4);
Telerik.Reporting.DetailSection detailSection = new Telerik.Reporting.DetailSection();
detailSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2);
report.Items.Add(detailSection);
Telerik.Reporting.TextBox 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);
detailSection.Items.Add(numberTextBox);
Telerik.Reporting.TextBox 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);
detailSection.Items.Add(nameTextBox);
Telerik.Reporting.SqlDataSource 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;
CopyVB.NET
Dim report As New Telerik.Reporting.Report()
report.Width = Telerik.Reporting.Drawing.Unit.Inch(4)
Dim detailSection As New Telerik.Reporting.DetailSection()
detailSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2)
report.Items.Add(detailSection)
Dim numberTextBox As 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)
detailSection.Items.Add(numberTextBox)
Dim nameTextBox As 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)
detailSection.Items.Add(nameTextBox)
Dim dataSource As 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 the report definition to an XML file:
CopyC#
using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create("Report.xml"))
{
Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();
xmlSerializer.Serialize(xmlWriter, report);
}
CopyVB.NET
Using xmlWriter As System.Xml.XmlWriter = System.Xml.XmlWriter.Create("Report.xml")
Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()
xmlSerializer.Serialize(xmlWriter, report)
End Using
Deserialize the report definition from a file:
CopyC#
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)
xmlSerializer.Deserialize(xmlReader);
}
CopyVB.NET
Dim settings As New XmlReaderSettings()
settings.IgnoreWhitespace = True
Using xmlReader As System.Xml.XmlReader = System.Xml.XmlReader.Create("Report1.xml", settings)
Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()
Dim report As Telerik.Reporting.Report = DirectCast(xmlSerializer.Deserialize(xmlReader), Telerik.Reporting.Report)
End Using
Serialized Report Definition in XML
CopyXML
<Report DataSourceName="sqlDataSource1" Width="4in" Name="userReport1" xmlns="http://schemas.telerik.com/reporting/2012/2">
<DataSources>
<SqlDataSource ConnectionString="Data Source=.\SqlExpress;Initial Catalog=AdventureWorks;Integrated Security=True" SelectCommand="select ProductNumber, Name from Production.Product" Name="sqlDataSource1" />
</DataSources>
<Items>
<DetailSection Height="0.2in" Name="detailSection1">
<Items>
<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" />
</Items>
</DetailSection>
</Items>
<PageSettings>
<PageSettings PaperKind="Letter" Landscape="False">
<Margins>
<MarginsU Left="1in" Right="1in" Top="1in" Bottom="1in" />
</Margins>
</PageSettings>
</PageSettings>
</Report>
Inheritance Hierarchy
Version Information
Supported in: 1.0.1
See Also