代码乱了(靳如坦的技术blog)

专注于.net,c#,Ajax、Sql Server、SmartClient等相关的开发
posts - 151, comments - 775, trackbacks - 13, articles - 2
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

Serialize and Deserialize RDL

Posted on 2011-03-23 23:30 代码乱了 阅读(79) 评论(0) 编辑 收藏


If you have a ReportViewer class generated from the XSD report definition file using:
xsd.exe /c /namespace:Rdl ReportDefinition.xsd

You can serialize and deserialize the class to/from RDLC XML:

xmldoc contains the XML RDLC code and is an XmlDocument.

Deserialization, from XML to Class

Rdl.Report report = new Rdl.Report();
XmlSerializer serializer = new XmlSerializer(typeof(Report));
XmlNodeReader xmlr = new XmlNodeReader(xmldoc);
report = (Rdl.Report)serializer.Deserialize(xmlr);

Now you can change the report elements using the objects and collections inside the
Rdl.Report class.

And Serialization, from Class to XML:

XmlDocument xmldoc = new XmlDocument();
StringBuilder sb = new StringBuilder();
MyStringWriterWithEncoding sw = new MyStringWriterWithEncoding(sb, System.Text.Encoding.UTF8);
serializer.Serialize(sw, report);
string sxml = sb.ToString();
xmldoc.LoadXml(sxml);

Here is a link to the ReportDefinition.cs class: