Ali Bigdeli
Ali Bigdeli

Reputation: 1375

how to change rdlc report items from deserialized rdlc file?

i want to find and change properties of report item element values in rdlc file. i deserialized ReportDefinition.xsd with xsd.exe tool :

using (TextReader textReader = new StreamReader(RdlcPath, Encoding.UTF8))
        {
            var serializer = new XmlSerializer(typeof(SampleRDLSchema.Report));
            Report instance = (SampleRDLSchema.Report)serializer.Deserialize(textReader);
            textReader.Close();
        }

but now how i can get change in report item element values?(for example change Tablix width or textbox content)

Upvotes: 0

Views: 2024

Answers (1)

Shelby115
Shelby115

Reputation: 2857

Like Jamie F stated, it would be easier to use formulas and expressions for the properties in the report. However, if you insist of doing it through XML manipulation, consider changing the xml instead of a deserialized object. The reason I say this is because it's cleaner. With the deserialized object you would have to do a loop, check if each object is the node you want, then continue this process until you have found the node you desire.

If the object is serialized and is in XML format as, say a string, you can simply use XElement to quickly grab things you want. Example: I use this to grab the width of the report from it's report definition (file xml string).

public String GetWidth()
{
     XElement Report = XElement.Parse(this._ReportDefinition);
     return Report.Element({http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Width").Value;
}

Or Another Example:

    // The grabs the names of all tablix report items from the report definition.
    public String GetReportItemName(String DataSetName)
    {
        XElement Report = XElement.Parse(this._ReportDefinition);

        String ReportItemName = String.Empty;
        XElement Body = Report.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Body");
        XElement ReportItems = Body.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}ReportItems");
        foreach (XElement ReportItem in ReportItems.Elements())
        {
            if (ReportItem.Name == "{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}Tablix")
            {
                String Name = ReportItem.Element("{http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition}DataSetName").Value;

                if (Name == DataSetName)
                {
                    ReportItemName = ReportItem.Attribute("Name").Value;
                }
            }
        }

        return ReportItemName;
    }

Hope this is of some help to you.

Upvotes: 1

Related Questions