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

5

18

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?

Onia answered 15/3, 2018 at 21:48 Comment(5)
Downvoter, care to tell me why is it down voted? I should be able to update the Question accordingly.Onia
1. What's the question? 2. If you are asking for similar too,s it's off-topic. Read this on how to ask on-topic questionsRiehl
@Riehl : I have rephrased the question. Hope this is clear now.Onia
Short answer, before leaving for bed: There are no controls and no aspx in ASP.NET Core. If you really rely on it, stick with ASP.NET MVC5 until all of your dependencies are available for .NET Standard/ASP.NET CoreRiehl
The question is mostly on "how to use microsoft report viewer on aspnet core project" . The implementation details can certainly differOnia
O
16

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."

Onia answered 24/4, 2018 at 19:6 Comment(1)
It's 2023. Did anything ever come of their purchase of Forerunner Software? The github issue is locked.Valdovinos
R
8

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)

Rothko answered 27/8, 2019 at 17:22 Comment(0)
G
4

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);
        }
    }
}
Grievous answered 25/3, 2018 at 17:22 Comment(10)
Thanks. I eventually travelled the route you have suggested. I wrote a small gist on my experience here. gist.github.com/codehippie1/d44701c48df252f30888c5cbcddd6fbeOnia
The gist gave way to this package. Could be useful to someone trying this route. npmjs.com/package/ng2-pdfjs-viewerOnia
Hello guys. Quick question: are you targeting net core 2.1 or the full network? The reason I ask is because targeting the net core won't build because it says that it requires IDataSource from System.Web. I've tried targeting the full net platform, but it still doesn't work if I'm using NLog for logging (not sure why)...Grattan
The example worked in .net Core 1.1 MVC app, but we have it implemented in a solution with .net Core MVC and .net 4.6 libraries, but no System.Web. It still compiles and executes fine, but in order to add a dataset based on a C# class to the report we need to temporarily move the RDLC to a .net MVC project referencing System.Web.Grievous
But if you generate the PDF directly, how can you make its layout?Ouachita
The layout is in the .rdlc file, created using the report editor in Visual Studio. The render method of the LocalReport creates the file in pdf format, by specifying the first parameter as "PDF". It could also be "Excel" or "Word".Grievous
This didn't work for me in a .net Core core project targeting Core 2.2. I got the error "System.TypeLoadException: 'Could not load type 'System.Web.UI.WebControls.CompositeControl' from assembly 'System.Web, Version=4.0.0.0". Has anyone made this work with a project targeting Core 2.2?Epistle
@LuisAbreu did you ever find a solution that worked with targeting Core 2.x?Epistle
Thanks for the update @LuisAbreu. I ended up adding a full .net framework Web API just for the rdlc's and referencing all our .Net Standard library code in there. I now have two sites, the Core one with the MVC UI and a the .Net Framework API one. That works for me as I was only using the ReportViewer to generate PDFs, not to actually view the reports.Epistle
I have something similar, but instead of using a full network web api app, I'm using a net core app that targets the full net framework (instead of net core). for now it's working, but if ms is serious about removing full net framework support from aspnet core projects, then I'm dead in the waterGrattan
W
2

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")
}
Winterkill answered 4/6, 2019 at 15:59 Comment(2)
Hello! Which assemblies are you referencing here?Laughlin
which libaray referring?Torose
C
0
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 );
}
Command answered 22/2, 2019 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.