Starting in 2019, the Reporting control is no longer included in Essential Studio®. If you're experiencing issues with the Syncfusion� Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion� and appreciate your understanding.

How to use ReportWriter with rdlc that contain subreport

Hi, i've manage to use reportwriter to generate PDF from a rdlc that contain no subreport.
But i got error when using rdlc with subreport in it. Do you have any code example for this case?

When applied to rdlc with subreport in it, i attach SubreportProcessing to update the subreport dataset, but looks like it was never been called which cause error no dataset when writing the PDF.

Code attached:
ReportWriter reportWriter = new ReportWriter(rdlcFilePath, rds);
reportWriter.ReportProcessingMode = ProcessingMode.Local;
if (reportParameters != null && reportParameters.Any())
    reportWriter.SetParameters(reportParameters);
reportWriter.SubreportProcessing += Rpt_SubRptProcessing;
           
            byte[] byteData = null;
            using (var ms = new MemoryStream())
            {
                reportWriter.Save(ms, WriterFormat.PDF);
                byteData = ms.ToArray();
            }

private void Rpt_SubRptProcessing(object sender, SubreportProcessingEventArgs e)
        {
            try
            {
                // get parameters
                var pageNum = Convert.ToInt32(e.Parameters["PageNum"].Values[0]);
                var hdId = Convert.ToInt32(e.Parameters["HdId"].Values[0]);

                // remove all previously attached Datasources, since we want to attach a new one
                e.DataSources.Clear();
                if (e.ReportPath.Contains("_rpt_Lamp2A"))
                {
                    e.DataSources.Add(new ReportDataSource()
                    {
                        Name = "DataSetA",
                        Value = GetSubRptDataSource()
                    });
                }
            }
            catch (Exception ex)
            {

            }
        }

3 Replies

YD Yuvaraj Devarajan Syncfusion Team February 12, 2018 06:51 AM UTC

Hi Edwin, 

Thanks for contacting Syncfusion support.  

We can set Subreport Datasource using the SubreportProcessing event available in ReportWriter and we request you to register the SubreportProcessing event before setting the report information’s ( ReportPath ,data source, parameters) as shown in the below code snippet.

 
public ActionResult Index(string writerFormat) 
        { 
            try 
            { 
                string fileName = null; 
                WriterFormat format; 
                HttpContext httpContext = System.Web.HttpContext.Current; 
                ReportWriter reportWriter = new ReportWriter();                                              
                reportWriter.SubreportProcessing += ReportWriter_SubreportProcessing; 
                reportWriter.ReportProcessingMode = ProcessingMode.Local;  
                reportWriter.ReportPath = Server.MapPath("~/App_Data/GroupingAgg.rdlc"); 
                reportWriter.DataSources.Clear(); 
                reportWriter.DataSources.Add(new ReportDataSource { Name = "Sales", Value = SalesDetails.GetData() }); 
 
                if (writerFormat == "PDF") 
                { 
                    fileName = "GroupingAgg.pdf"; 
                    format = WriterFormat.PDF; 
                } 
                else if (writerFormat == "Word") 
                { 
                    fileName = "GroupingAgg.doc"; 
                    format = WriterFormat.Word; 
                } 
                else if (writerFormat == "Html") 
                { 
                    fileName = "GroupingAgg.Html"; 
                    format = WriterFormat.HTML; 
                } 
                else if (writerFormat == "Csv") 
                { 
                    fileName = "GroupingAgg.csv"; 
                    format = WriterFormat.CSV; 
                } 
                else 
                { 
                    fileName = "GroupingAgg.xls"; 
                    format = WriterFormat.Excel; 
                } 
                reportWriter.Save(fileName, format, httpContext.Response); 
            } 
            catch 
            { 
            } 
            return View(); 
        } 

We have prepared a sample based on your requirement and it can be downloaded from the following location.
http://www.syncfusion.com/downloads/support/directtrac/general/ze/ReportWriterMvc911396254.zip  

Regards, 
Yuvaraj D. 



EK Edwin Kurniawan February 15, 2018 07:43 AM UTC

It seems that i was using an async method when preparing the datasource in the SubreportProcessing event handler which likely not supported or i don't know the other causes and that is why my datasource is null.

Thank you for the response, Yuvaraj


YD Yuvaraj Devarajan Syncfusion Team February 16, 2018 11:19 AM UTC

Hi Edwin, 

We cannot pass the asynchronous datasource value for subreport in the SubreportProcessing event. We request you to get the datasource values synchronously and set it in the SubreportProcessing event to render the report with data.    

Regards, 
Yuvaraj D. 


Loader.
Up arrow icon