This is a migrated thread and some comments may be shown as answers.

Set report source dynamically in trdp file.

1 Answer 1492 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Deepak
Top achievements
Rank 1
Deepak asked on 18 Jul 2019, 07:46 AM
Can we set report data  source dynamically in .trdp file, without using the wizard?

1 Answer, 1 is accepted

Sort by
0
Silviya
Telerik team
answered on 23 Jul 2019, 05:58 AM
Hello Deepak,

I noticed that you've opened a support ticket on the same topic. I'll post my answer here as well:

'If I understood the requirement correctly, you need to set the data source of the report created with our Standalone Report Designer, from code-behind. Also, I assume that the datasource will be either coming from a web service or an inline JSON file.

When working with TRDP reports you can use the ReportPackager class to unpackage the report. For more information, please check the Report Unpackaging help article. The ReportPackager.Unpackage Method will return a Telerik.Reporting.Report object which you can use and modify.

When report is served by Reporting REST service to HTML5 report viewer, all run-time modifications to report need to happen in custom report resolver used by the service. So, the steps would be the following:

1. Unpackage the TRDP report to apply modifications:
var reportPackager = new ReportPackager();
using (var sourceStream = System.IO.File.OpenRead("Report1.trdp"))
{
    var report = (Report)reportPackager.UnpackageDocument(sourceStream);
}

2. After you have the report object available, you can modify its definition based on the Reporting API Reference:
//create the data source
report.DataSource = //assign new data source here
var irs = new InstanceReportSource();
irs.ReportDocument = report;
this.reportViewer1.ReportSource = irs;

 Note that the instantiated report will be passed to the reporting engine wrapped in an InstanceReportSource. It is important that resolver's Resolve() method returns the same report source for the same value of the string passed with reportSource.report option of the viewer.
'


Best Regards,
Silviya
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Deepak
Top achievements
Rank 1
Answers by
Silviya
Telerik team
Share this question
or