Articles in this section
Category / Section

How to export the RDLC subreport in Core ReportWriter

1 min read

Render RDLC main and subreport

 

If we render the RDLC main and subreport then we need to load the subreport stream before loading the main report stream in ASP.NET Core ReportWriter control. Then create the SubreportProcessing event to passing the dataset collections for subreport.

 

Find the below code snippet for your reference for how to load the multiple subreport in ReportWriter control.

[HttpPost]
        public IActionResult Pdf()
        {
 
            string basePath = _hostingEnvironment.WebRootPath;
            // Here, we have loaded the sample report report from application the folder wwwroot. 
            // Invoice.rdl should be there in wwwroot application folder.
            FileStream inputStream = new FileStream(basePath + @"\Reports\MainReport.rdlc", FileMode.Open, FileAccess.Read);
            FileStream subreport1 = new FileStream(basePath + @"\Reports\SubReport1.rdlc", FileMode.Open, FileAccess.Read);
            FileStream subreport2 = new FileStream(basePath + @"\Reports\SubReport2.rdlc", FileMode.Open, FileAccess.Read);
            ReportWriter writer = new ReportWriter();
            writer.ReportProcessingMode = ProcessingMode.Local;
            writer.SubreportProcessing += ReportWriter_SubreportProcessing;
            writer.LoadSubreport("SubReport1", subreport1);
            writer.LoadSubreport("SubReport2", subreport2);
            writer.LoadReport(inputStream);
 
            writer.DataSources.Clear();
            writer.DataSources.Add(new ReportDataSource { Name = "DataSet", Value = MainReport.GetData() });
 
            // Steps to generate PDF report using Report Writer. 
            MemoryStream memoryStream = new MemoryStream();
            writer.Save(memoryStream, WriterFormat.PDF);
 
            // Download the generated from client.
            memoryStream.Position = 0;
            FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/pdf");
            fileStreamResult.FileDownloadName = "Invoice.pdf";
            return fileStreamResult;
        }
 
        private void ReportWriter_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
        {
            if (e.ReportPath == "SubReport1")
            {
                e.DataSources.Clear();
                e.DataSources.Add(new ReportDataSource { Name = "DataSet1", Value = SubReport.GetData() });
            }
            else if (e.ReportPath == "SubReport2")
            {
                e.DataSources.Clear();
                e.DataSources.Add(new ReportDataSource { Name = "DataSet2", Value = SubReport.GetData() });
            }
        }

 

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ReportSample_core_2.0--1662259462.zip

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied