Articles in this section
Category / Section

How to edit a report at runtime in LightSwitch HTML ?

1 min read

A report (RDL/RDLC) can be edited or modified at runtime using ReportDefinition class. The following describes the steps to edit a report at runtime and render the output.

  1. To edit existing report, it need to be de serialized to Report Definition object using XmlSerializer.


FileStream stream = new FileStream(info.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
XElement rdl = XElement.Load(XmlReader.Create(stream));
string Namespace = (from attribute in rdl.Attributes() where attribute.Name.LocalName == "xmlns" select attribute.Value).FirstOrDefault();
XmlSerializer xs = new XmlSerializer(typeof(Syncfusion.RDL.DOM.ReportDefinition), Namespace);
using (StringReader reader = new StringReader(rdl.ToString()))
   reportDefinition = (Syncfusion.RDL.DOM.ReportDefinition)xs.Deserialize(reader);
  1. The serialized report definition object contains all the properties available in report file. The properties of each XML element can accessed and updated to required values. In the below code, value of a text box report item in page header is updated with new value.


var data = reportDefinition.ReportSections[0];
//=====Edit Report item in report header =========//
Syncfusion.RDL.DOM.TextBox headertext = new Syncfusion.RDL.DOM.TextBox();
headertext = (Syncfusion.RDL.DOM.TextBox)data.Page.PageHeader.ReportItems[0];
headertext.Paragraphs[0].TextRuns[0].Value = table.Columns[0].ToString();
  1. The below code used to edit Tablix report item and its inner cell element value in report.


Syncfusion.RDL.DOM.Tablix reportitem = new Syncfusion.RDL.DOM.Tablix();
reportitem = (Syncfusion.RDL.DOM.Tablix)data.Body.ReportItems[0];            
for (int i = 0; i < table.Columns.Count; i++)
  Syncfusion.RDL.DOM.TextBox txtbox = new Syncfusion.RDL.DOM.TextBox();
  txtbox = (Syncfusion.RDL.DOM.TextBox)reportitem.TablixBody.TablixRows[0].TablixCells[i].CellContents.ReportItem;
  txtbox.Paragraphs[0].TextRuns[0].Value = table.Columns[i].ToString();     
  1. The modified report definition can be converted as stream or saved into a local file using the XmlSerializer’s Deserialize method.


string nameSpace = "";
if (reportDefinition.RDLType == Syncfusion.RDL.DOM.RDLType.RDL2010)
    nameSpace = "";
System.Xml.Serialization.XmlSerializerNamespaces serialize = new System.Xml.Serialization.XmlSerializerNamespaces();
serialize.Add("rd", "");
XmlSerializer xs2 = new XmlSerializer(typeof(Syncfusion.RDL.DOM.ReportDefinition), nameSpace);
MemoryStream memoryStream = new MemoryStream();
TextWriter ws2 = new StreamWriter(memoryStream);
xs2.Serialize(ws2, reportDefinition, serialize);
memoryStream.Position = 0;






Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment