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

Loading report from file

1 Answer 396 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nikita
Top achievements
Rank 1
Nikita asked on 05 Apr 2017, 06:11 PM

How can i load report from file and change data source?

 

For example:

I have "report1.trdp", saved in "c:\reports". 

MyRptService needs to open it, pass data as object collection (matching field names in report) and output to pdf.

In below example I can open report and output to pdf but I dont see any way to set different datasource

 Telerik.Reporting.Processing.ReportProcessor reportProcessor =
                    new Telerik.Reporting.Processing.ReportProcessor();

                // set any deviceInfo settings if necessary
                System.Collections.Hashtable deviceInfo =
                    new System.Collections.Hashtable();

                var uriReportSource = new Telerik.Reporting.UriReportSource();

                // Specifying an URL or a file path
                uriReportSource.Uri = @"C:\data\reports\Report1.trdp";

                    

                Telerik.Reporting.Processing.RenderingResult result =
                    reportProcessor.RenderReport("PDF", uriReportSource, deviceInfo);

                string fileName = result.DocumentName + "." + result.Extension;
                string path = System.IO.Path.GetTempPath();
                string filePath = System.IO.Path.Combine(path, fileName);

                using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
                {
                    fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
                }

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 10 Apr 2017, 09:28 AM
Hello Nikita,

To change data sources, you need to get all data items having a DataSource property and to update them. Please consider the example in Changing the connection string dynamically according to runtime data, where the path to TRDP|TRDX files must be adjusted and you need to add case for unpackaging TRDP files.

Let us know if you need further help.

Regards,
Stef
Telerik by Progress
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
Nikita
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or