An error occurred during report processing. -RLDC reporting in ASP.NET MVC

后端 未结 3 893
野趣味
野趣味 2020-11-27 22:59

I have this action to generate reports :

  public ActionResult Report(string id)
        {
            LocalReport lr = new LocalReport();
            strin         


        
3条回答
  •  感情败类
    2020-11-27 23:45

    My solution for rdlc is based on ReportViewer.

            byte[] bytes = null;
            string attachmentName = string.Empty;
    
            Warning[] warnings;
            string[] streamids;
            string mimeType;
            string encoding;
            string extension;
            /*GetReportDataSources(logicResult, spec);*/
            var reportPath = GetReportExecutionPath();
    
            ReportViewer viewer = new ReportViewer();
            /*viewer.LocalReport.SubreportProcessing +=
                new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(LocalReport_SubreportProcessing);*/
            viewer.LocalReport.ReportPath = reportPath;
            /*viewer.LocalReport.SetParameters(parameters);*/
            viewer.LocalReport.EnableExternalImages = true;
            viewer.RefreshReport();
    
            viewer.LocalReport.DisplayName = "displayName";
            bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension,
                out streamids, out warnings);
    

    /*some logic */

            return new StreamResponse(() =>
            {
                var pdfOutput = new MemoryStream(bytes); 
                pdfOutput.Seek(0, SeekOrigin.Begin);
                return pdfOutput;
            }, "application/pdf").WithHeader("Content-Disposition", "attachment; filename=" + attachmentName);
    

    You need also add report path, and datasources (my solution is complicated, and I use for that LocalReport_SubreportProcessing).

    P.S. Using rdlc with ASP.MVC have 1 issue. You need set on ISS App Pool "Identity = LocalSystem", that is ok in Intranet, but not ok in Internet.

提交回复
热议问题