Set datasource to UriReportSource

2 posts, 0 answers
  1. Emmanuel
    Emmanuel avatar
    10 posts
    Member since:
    Feb 2012

    Posted 10 Jul Link to this post

    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;
            }

     

     

  2. Nasko
    Admin
    Nasko avatar
    1023 posts

    Posted 10 Jul Link to this post

    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
Back to Top