AR 17 Attempting to Export Report - Error Unknown Data Source on XmlReader

Posted by: mlocke on 19 April 2023, 1:09 pm EST

    • Post Options:
    • Link

    Posted 19 April 2023, 1:09 pm EST - Updated 19 April 2023, 3:54 pm EST

    Hi!

    I have a multi-section report in AR 17 that I’m trying to export via code. This is what I have:

                    SectionReport sectionReport = new SectionReport();
                    XmlReader xtr = XmlReader.Create("C:\\My Dev\\PDSAPI\\PDSAPI\\Reports\\MFS.rdlx");
                    sectionReport.LoadLayout(xtr);
    
                    sectionReport.Parameters[0].Value = mfsRecordKey.ToString();
                    sectionReport.Run();
    
    
                    GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
                    // Add meta data
                    var metadata1 = new AdditionalMetadataInfo
                    {
                        Namespace = AdditionalMetadataNamespace.PurlOrg, //Dublin Core Properties
                        Key = "title",
                        Value = "MFSReport"
                    };
    
                    pdfExport.Options.AdditionalMetadata.Add(metadata1);
                    pdfExport.Export(sectionReport.Document, "C:\\Users\\someName\\Downloads");

    On the line to call sectionReport.LoadLayout(xtr) - it gives this error: “Unknown DataSource name:DataSource”. When I inspect the xtr object, it just says “none” but the base uri is fine. The report has a datasource added pointing to our sql server and the report uses 2 stored procedures to pull fields from. When previewing the report in the designer, data is pulled back as expected.

    How can I get this to work? Basically, I’ll be calling this service application code from multiple projects - winforms app, website, angularjs site - and I want to be able to pass the 1 parameter it needs and export to PDF without showing the report in any type of viewer.

    Thanks!

    Answer for those that need it:

    The report “ActiveReport RDL Multi-Section Report” is not a section report. It’s a page report and needs different rendering code.

                 PageReport pageReport = new PageReport();
    
                    System.IO.FileInfo fi = new System.IO.FileInfo("C:\\My Dev\\PDSAPI\\PDSAPI\\Reports\\MFS.rdlx");
    
                    pageReport.Load(fi);
                    pageReport.Report.ReportParameters[0].DefaultValue.Values.Add(mfsRecordKey.ToString());
                    
                    pageReport.Run();
    
                    // Provide settings for your rendering output.
                    GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
    
                    // Set the rendering extension and render the report.
                    GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new
                            GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
                    System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyPDF");
                    outputDirectory.Create();
                    GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory,
                            System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
    
                    // Overwrite output file if it already exists
                    outputProvider.OverwriteOutputFile = true;
    
                    pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
  • Posted 20 April 2023, 2:36 am EST

    Hi Melissa,

    Correct, you need to load your Page/RDL report into a PageReport object and use the ‘PDFRenderingExtension’ class to export your report into a PDF.

    We’re glad you were able to resolve the issue!

    We have attached a sample implementing the same for anyone needing a reference project. To learn more about exporting your RDL/Page report to PDF please refer to: https://www.grapecity.com/activereportsnet/docs/latest/online/pdf-export-page-rdl.html

    Regards,

    Anand

    RDLReportExportToPDF.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels