Category / Section
Converting a Report to C# Object Model using ReportSerializer in Bold Reports
Published:
Updated:
This code sample demonstrates the process of converting a report into a C# object model using the ReportSerializer helper from Bold Reports. The resulting C# object model allows for runtime modifications of the report. The following steps outline how to obtain the report in the C# object model using the Report Serializer:
FileStream fileStream = new FileStream( reportFolderPath + "\Resources\sales.rdl", FileMode.Open, FileAccess.Read);
MemoryStream reportStream = new MemoryStream();
fileStream.CopyTo(reportStream);
reportStream.Position = 0;
fileStream.Close();
BoldReports.RDL.DOM.ReportSerializer reportSerializer = new BoldReports.RDL.DOM.ReportSerializer();
// Method to get the reports with the ReportDefinition object model.
var reportDefinition = reportSerializer.GetReportDefinition(reportStream);
// Property to get the parameters information from the report.
var reportParameters = reportDefinition.ReportParameters;
// Property to get the data sources information from the report.
var reportDatasources = reportDefinition.DataSources;
// Property to get the datasets from the report.
var dataSets = reportDefinition.DataSets;
// Property to get the report items information from the report body.
BoldReports.RDL.DOM.ReportItems bodyReportItems = reportDefinition.ReportSections[0].Body.ReportItems;
// Property to get the report items information from the report header.
var headerReportItems = reportDefinition.ReportSections[0].Page.PageHeader.ReportItems;
// Property to get the report items information from the report footer.
var footerReportItems = reportDefinition.ReportSections[0].Page.PageFooter.ReportItems;
In summary, this code showcases how to convert a report file into a C# object model using the ReportSerializer helper, enabling runtime modification of the report.