How do you create a ReportBook object from a .trbp file programmatically?

1 Answer 184 Views
.NET Framework Programming Rendering Report Book Report Designer (standalone)
Jason
Top achievements
Rank 1
Iron
Jason asked on 23 May 2023, 05:06 PM

We have a custom report screen that uses multiple reporting frameworks to render reports as files (typically Excel). The available reports are loaded dynamically at runtime, the user picks a report which retrieves and displays the report parameters for the users to enter values, and then the report can be rendered to the file type that they choose.

We will be creating single reports (.trdp files) and report books (.trbp files) and uploading those onto the server for use with this screen. We are currently using the R1 2023 Reporting framework. Our application is written in c# and uses .NET Framework 4.8.

I have almost everything working with the Telerik framework but cannot find anywhere to create a ReportBook object from a .trbp file. The closest I found was this forum post (https://www.telerik.com/forums/reportbook-by-path-name)and this article on Deserializing from XML (https://docs.telerik.com/reporting/embedding-reports/program-the-report-definition/serialize-report-definition-in-xml). This does not work and I assume things have totally changed given the post was over 10 years old.

Using the code below gives the exception "Data at the root level is invalid. Line 1, position 1." The .trbp file that we are attempting to load was designed using the Telerik Standalone Report Designer.

var reportBook = new Telerik.Reporting.ReportBook();

using (System.IO.FileStream stream = new System.IO.FileStream(reportPath, System.IO.FileMode.Open))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer = new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();                    
    reportBook = (Telerik.Reporting.ReportBook)xmlSerializer.Deserialize(stream);
}

Is it possible to load a .trbp file into a ReportBook object? If so, how?

Thanks,

Jason

1 Answer, 1 is accepted

Sort by
0
Accepted
Jason
Top achievements
Rank 1
Iron
answered on 25 May 2023, 05:02 PM

For anyone out there looking for a solution, I finally found it:

Telerik.Reporting.ReportBook reportBook = null;

using (var reportStream = File.OpenRead(reportPath))
{
    var reportPackager = new Telerik.Reporting.ReportPackager();
    reportBook = (Telerik.Reporting.ReportBook)reportPackager.UnpackageDocument(reportStream);    
}

It would be helpful if the API documentation was up-to-date, or at least accurate/complete - the documentation for the ReportPackager class (https://docs.telerik.com/reporting/api/telerik.reporting.reportpackager) explicitly states:

Packages and unpackages report documents in TRDP format. This is a zipped, XML-based file format for representing report documents. Starting with Telerik Reporting Q2 2016, the TRDP have become the default target file format for Telerik Report Designer and Telerik Report Server.

There is nothing in the documentation that says this can be used for ReportBooks. I'm thinking that the ReportPackager class *might* be able to work with loading other objects from file as well.

Tags
.NET Framework Programming Rendering Report Book Report Designer (standalone)
Asked by
Jason
Top achievements
Rank 1
Iron
Answers by
Jason
Top achievements
Rank 1
Iron
Share this question
or