RDLC Local report viewer for ASP.NET Core and Angular(>2.0)

前端 未结 5 1472
-上瘾入骨i
-上瘾入骨i 2020-12-08 11:38

Is there any way to show RDLC Local ReportViewer control in asp.net core webpage?

To show a ReportViewer, on a traditional WebForms application, the below code works

5条回答
  •  旧巷少年郎
    2020-12-08 12:25

    If the question is how to use Microsoft Reportviewer on ASP.NET Core project, regardless of implementation details, my solution is to bypass the actual reportviewer control and render reports directly to PDF or Excel. It works in .net Core 1.1. NuGet package we use is Microsoft.ReportViewer.2012.Runtime by Fornax.

    using System.IO;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Reporting.WebForms;
    
    namespace WebApplication3.Controllers
    {
        public class ReportController : Controller
        {
            private readonly IHostingEnvironment environment = null;
            public ReportController(IHostingEnvironment environment)
            {
                this.environment = environment;
            }
            public IActionResult Report()
            {
                string mimeType;
                string encoding;
                string filenameExtension;
                string[] streams;
                Warning[] warnings;
                var rv = new ReportViewer();
                rv.ProcessingMode = ProcessingMode.Local;
                rv.LocalReport.ReportPath = Path.Combine(environment.ContentRootPath, "Reports", "Report1.rdlc");
                rv.LocalReport.Refresh();
                var bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streams, out warnings);
                return File(bytes, mimeType);
            }
        }
    }
    

提交回复
热议问题