This is a migrated thread and some comments may be shown as answers.
Set datasource to UriReportSource
1 Answer 140 Views
This is a migrated thread and some comments may be shown as answers.
Emmanuel
Top achievements
Rank 1
Emmanuel asked on 10 Jul 2018, 10:15 AM

Hello,

I use on asp.net UriReportSource to produce PDF invoice.

The datasource is now set on trdx file, I would like change the method.

I need to pass datasource from code c#, not set on file trdx.

Could you help me ?

Thank you.

public string GetInvoice()
        {
            string fileName = Path.GetTempPath() + (Guid.NewGuid()).ToString() + ".pdf";
            UriReportSource uriReportSource = GetInvoiceUriReportSource();
            ExportToPDF(GetReport(uriReportSource), fileName);
 
            return fileName;
        }
 
        private void ExportToPDF(UriReportSource reportToExport, string fileName)
        {
            ReportProcessor reportProcessor = new ReportProcessor();
            RenderingResult result = reportProcessor.RenderReport("PDF", reportToExport, null);
            using (FileStream fs = new FileStream(fileName, FileMode.Append))
            {
                fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            }
        }
 
 
        private UriReportSource GetInvoiceUriReportSource()
        {
            UriReportSource uriReportSource = new Telerik.Reporting.UriReportSource();
            if (HostingEnvironment.ApplicationPhysicalPath != null)
                uriReportSource.Uri = HostingEnvironment.ApplicationPhysicalPath + SettingType.TemplateFacture.GetValue();
            else
                uriReportSource.Uri = Directory.GetCurrentDirectory() + SettingType.TemplateFacture.GetValue();
 
             
            return GetReport(uriReportSource);
        }
 
        private UriReportSource GetReport(UriReportSource report, int documentRowId = -1)
        {
                        
 
            report.Parameters.Add(new Telerik.Reporting.Parameter("DocumentID", DocumentId));
            report.Parameters.Add(new Telerik.Reporting.Parameter("DocumentLigneID", documentRowId));
            report.Parameters.Add(new Telerik.Reporting.Parameter("SocieteNom", SettingType.SocieteNom.GetValue()));
            report.Parameters.Add(new Telerik.Reporting.Parameter("SocieteAdresse", SettingType.SocieteAdresse.GetValue()));
            report.Parameters.Add(new Telerik.Reporting.Parameter("SocieteCPVille", SettingType.SocieteCPVille.GetValue()));
            report.Parameters.Add(new Telerik.Reporting.Parameter("SocieteSiret", SettingType.SocieteSiret.GetValue()));
            report.Parameters.Add(new Telerik.Reporting.Parameter("SocieteTEL", SettingType.SocieteTEL.GetValue()));
 
            
 
            return report;
        }

 

 

1 Answer, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 10 Jul 2018, 03:18 PM
Hello Emmanuel,

To modify the report wrapped by the UriReportSource you will first need to deserialize it to a report object - Deserialize from XML.

Then you can use the modified report object in the report viewer by wrapping it in an InstanceReportSource.

Regards,
Nasko
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
Asked by
Emmanuel
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Share this question
or