0

When using VS2015 or higher to edit an SSRS report, the XML generated is not compatible with Reporting Services 2012. We need to modify a couple of things. I'm trying to write a script that will just do that, programmatically.

I got the code to replace the xmlns definition and the code to remove the entire node .

I don't know how to REMOVE and KEEPING the childern. (using C#)

<ReportSections>
  <ReportSection>
    <Body></Body>
    <Width></Width>
    ...
  </ReportSection>
</ReportSection>



//THIS CODE DOES NOT WORK
//Remove <ReportSections></ReportSections>  <ReportSection>/<ReportSection>
foreach (XmlNode child in rnode.ChildNodes)
{
    if(child.Name.Equals("ReportSections", 
       StringComparison.InvariantCultureIgnoreCase))
    {
        child.ParentNode.AppendChild(child);
    }
        child.ParentNode.RemoveChild(child);
}

This is the code I wrote to delete including the childern.

//Remove <ReportParameters>...</ReportParameters> and all its content
foreach (XmlNode xNode in rnode.ChildNodes)
{
    if (xNode.Name.Equals("ReportParameters", StringComparison.InvariantCultureIgnoreCase))
    {
       xNode.ParentNode.RemoveChild(xNode);
    }
}
  • Why not just set the TargetServerVersion and have Visual Studio generate the correct report definition for you? – Dale K Feb 14 '19 at 02:31
  • Possible duplicate of [SSRS report definition is newer than Server](https://stackoverflow.com/questions/38902037/ssrs-report-definition-is-newer-than-server) – Dale K Feb 14 '19 at 09:41

1 Answers1

0

This is my working solution

//Remove <ReportSections></ReportSections>  <ReportSection>/<ReportSection>
                foreach (XmlNode rootChild in rnode.ChildNodes)
                {
                    if (rootChild.Name.Equals("ReportSections", StringComparison.InvariantCultureIgnoreCase))
                    {
                        foreach (XmlNode reportSectionsChild in rootChild.ChildNodes)
                        {
                            if (reportSectionsChild.Name.Equals("ReportSection", StringComparison.InvariantCultureIgnoreCase))
                            {
                                foreach(XmlNode reportSectionChild in reportSectionsChild.ChildNodes)
                                {
                                    reportSectionChildren.Add(reportSectionChild);
                                } 
                            }
                        }

                        rootChild.ParentNode.RemoveChild(rootChild);
                    }

                }

                foreach (var child in reportSectionChildren)
                {
                    rnode.AppendChild(child);
                }