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

丶灬走出姿态 提交于 2019-11-27 13:14:23

问题


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.

<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

        <div style="height: 600px;">
            <rsweb:ReportViewer ID="reportViewer" runat="server" Width="100%" Height="100%"></rsweb:ReportViewer>
        </div>
    </form>
</body>

I have already tried and tested the below components. The results are given below.

  1. ReportViewerForMvc - Works for MVC, but not compatible with ASPNET Core.
  2. MvcReportViewer - Works for MVC, but not compatible with ASPNET Core(See this issue: https://github.com/ilich/MvcReportViewer/issues/121).
  3. MvcReportViewer - Does not use microsoft viewer control, thus supports aspnet core, but does not work with Local Reports(Need a report server url).
  4. ngx-ssrs-reportviewer npm package - A wrapper over Remote Reports, does not supports Local reports.(Need a report server url)

Q1. What is the best approach to use <rsweb:ReportViewer> in asp.net core application?


回答1:


Found an npm package ng2-pdfjs-viewer, though it is not quite the MS report viewer, if you are willing to use PDFJS, the documentation of the package has an example on similar lines to use LocalReport viewer for generating pdf and ng2-pdfjs-viewer to display it in browser - (https://www.npmjs.com/package/ng2-pdfjs-viewer)

<!-- your.component.html -->
<button (click)="openPdf();">Open Pdf</button>
<!-- your.component.ts-->
export class MyComponent implements OnInit {
  @ViewChild('pdfViewer') pdfViewer
  ...

  private downloadFile(url: string): any {
    return this.http.get(url, { responseType: ResponseContentType.Blob }).map(
      (res) => {
        return new Blob([res.blob()], { type: "application/pdf" });
      });
  }

  public openPdf() {
    let url = "http://localhost:4200/api/GetMyPdf
    this.downloadFile(url).subscribe(
    (res) => {
        this.pdfViewer.pdfSrc = res; // pdfSrc can be Blob or Uint8Array
        this.pdfViewer.refresh(); // Ask pdf viewer to load/reresh pdf
      }
    );
  }
[HttpGet]
[Route("MyReport")]
public IActionResult GetReport()
{
   var reportViewer = new ReportViewer {ProcessingMode = ProcessingMode.Local};
   reportViewer.LocalReport.ReportPath = "Reports/MyReport.rdlc";

   reportViewer.LocalReport.DataSources.Add(new ReportDataSource("NameOfDataSource1", reportObjectList1));
   reportViewer.LocalReport.DataSources.Add(new ReportDataSource("NameOfDataSource2", reportObjectList1));

   Warning[] warnings;
   string[] streamids;
   string mimeType;
   string encoding;
   string extension;

   var bytes = reportViewer.LocalReport.Render("application/pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings);

   return File(bytes, "application/pdf")
}



回答2:


Microsoft is not implementing or bringing RDLC report viewer into aspnet core. Instead they are purchasing a product to fill the void.

Full link to news - https://blogs.msdn.microsoft.com/sqlrsteamblog/2018/04/02/microsoft-acquires-report-rendering-technology-from-forerunner-software/

Link to original issue - https://github.com/aspnet/Home/issues/1528

Here is the essence. "Microsoft acquires report rendering technology from Forerunner Software

We’re pleased to announce that we’ve acquired technology from Forerunner Software to accelerate our investments in Reporting Services. This technology includes, among other things, client-side rendering of Reporting Services (*.rdl) reports, responsive UI widgets for viewing reports, and a JavaScript SDK for integrating reports into other apps – a testament to what our partners can achieve building on our open platform.

This is great news for you, as we see opportunities to apply this technology to multiple points of feedback we’ve heard from you:

You’re looking for cloud Software-as-a-Service (SaaS) or Platform-as-a-Service (PaaS) that can run SSRS reports. As you might’ve seen in our Spring ’18 Release Notes, we’re actively working on bringing SSRS reports to the Power BI cloud service, and we’re building on client-side rendering to make that possible. You want to view SSRS reports on your phone, perhaps using the Power BI app. We believe this technology will help us deliver better, more responsive UI for supplying report parameter values, navigating within reports, and possibly even viewing report content.

You love the Report Viewer control… but it’s an ASP.NET Web Forms control. You need something you can integrate into your ASP.NET Core/MVC app or non-ASP.NET app. With this technology, we hope to deliver a client-side/JavaScript-based Report Viewer you can integrate into any modern app.

These are large undertakings and we don’t yet have timeframes to share, but stay tuned over the coming months as we always strive to share our progress with you and hear your feedback as early and often as we can.

Forerunner Software will continue to support existing customers for a limited period of time."




回答3:


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);
        }
    }
}



回答4:


In order for Jame's solution to work - it requires that you reference the full .NET Framework. This is all well and good for ASP.NET Core 1 and 2, however - as everyone should be aware by now - ASP .NET 3 will NOT allow you to reference the full .NET Framework.

Currently, it's only possible to use SSRS hosted server reports (RDL) reports with .NET Core. For client RDLC reports, currently only the paid Syncfusion solution works (I've tested the trail version)

James solution will is entirely invalid with ASP.NET Core 3 (which again - only allows you to reference .NET Core - not the .NET Framework)




回答5:


public List<object> _dataSourceList = new List<object>();
public string _dataSourceName { get; set; }

public string _reportPath = CommonUtil.Report_path; //set your report path in app.config file
public Dictionary<string, string> Parameters = new Dictionary<string, string>();

public void PDFPrint_Load() {

  string mimtype="";
  int extension = 1;

  LocalReport localReport= new LocalReport(_reportPath);
  localReport.AddDataSource(_dataSourceName, _dataSourceList);

  if (Parameters != null && Parameters.Count > 0)// if you use parameter in report
  {
    List<ReportParameter> reportparameter = new List<ReportParameter>();
    foreach (var record in Parameters) {
      reportparameter.Add(new ReportParameter());
    }
  }
  var result = localReport.Execute(RenderType.Pdf, extension,parameters: 
  Parameters, mimtype);

  byte[] bytes = result.MainStream;
  string fileName = "Report.pdf";
  return File(bytes , "application/pdf",fileName );
}


来源:https://stackoverflow.com/questions/49309797/rdlc-local-report-viewer-for-asp-net-core-and-angular2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!