How to display ReportBook in viewer
Environment
Product | Progress® Telerik® Reporting |
Description
This article demonstrates the three approaches for displaying ReportBook in an application. It is applicable for any application type. Depending on the report viewer, there might be different approaches for setting the viewer's ReportSource, all of them can be reviewed in How to: Set ReportSource for Report Viewers help article.
Solution
-
ReportBook can be created in Standalone report designer first using Report Book report template. The output will be a .TRBP file that can be passed to report viewer's report source as UriReportSource.
// HTML5 Report Viewer example initialization reportSource: { report: "ReportBook1.trbp" }
Create a ReportBook by inheriting Telerik.Reporting.ReportBook class and adding the required ReportSources to it. An example of it is provided in ReportBook.cs file located in product installation folder (C:\Program Files (x86)\Progress\Telerik Reporting VERSION\Examples\CSharp\ReportLibrary\ReportBook). Created ReportBook can be passed to the report viewer's report source as TypeReportSource.
-
(not recommended) ReportBook can be created at run-time: How to: Create a Report Book at run-time. This approach is only valid when you need to create/modify report definitions at run-time. The created instance of the ReportBook can be passed to the viewer's report source using InstanceReportSource. This approach relies on custom report resolver logic to add the reports into the report book and return the new instance of the report book. For example:
public class MyReportSourceResolver : IReportSourceResolver { public ReportSource Resolve(string reportId, OperationOrigin operationOrigin, IDictionary<string, object> currentParameterValues) { // Creating a new report book var reportBook = new ReportBook(); //Add first report var firstReportSource = new TypeReportSource(); firstReportSource.TypeName = typeof(FirstReport).AssemblyQualifiedName; reportBook.ReportSources.Add(firstReportSource); //Add second report var secondReportSource = new TypeReportSource(); secondReportSource.TypeName = typeof(SecondReport).AssemblyQualifiedName; reportBook.ReportSources.Add(secondReportSource); //Return the new instance var result = new InstanceReportSource { ReportDocument = reportBook }; return result; } }
Then go to ReportsController.cs and change the resolver:
//Setup the ReportServiceConfiguration configurationInstance = new ReportServiceConfiguration { HostAppId = "Html5App", Storage = new FileStorage(), ReportSourceResolver = new MyReportSourceResolver() };