PageReport serialize to XML

Posted by: mdynna on 15 June 2023, 12:32 pm EST

    • Post Options:
    • Link

    Posted 15 June 2023, 12:32 pm EST

    The Save method on a PageReport can be passed a FileInfo object and the result is essentially the report serializing itself to XML into the file. Rather than saving to file I would like to write this information into our database so that custom reports are stored internally. Can this serialization process be redirected into some kind of variable that I can then save to the database? I see that the method can be passed an XmlWriter object, but that seems to imply that a whole new derived class will need to be written with the logic for translating the report into XML. I would just like to have it do whatever it does when saving to file, but redirect the output. Is that possible?

  • Posted 20 June 2023, 12:03 am EST

    Hi Mark,

    Yes, you can save your report to an XMLWriter which you can store in a MemoryStream, and then convert your MemoryStream to a Byte array that you can store in your database.

    Please refer to the code snippet below:

    MemoryStream stream;
    PageReport report = new PageReport(new FileInfo(Application.StartupPath + @"\..\..\RdlReport1.rdlx"));
    stream = new MemoryStream();
    var writer = XmlWriter.Create(stream);
    report.Save(writer);
    writer.Flush();
    stream.Position = 0;
    byte[] reportBytes = stream.ToArray(); // You can save this byte[] in your database
    

    Please find attached a sample implementing the same.

    Regards,

    Anand

    MemoryStreamToByteArray.zip

  • Posted 20 June 2023, 5:10 pm EST

    Oh, I was so close! Thanks that works.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels