16

Is it possible to render .rdlc reports with ASP.NET Core? Currently this only seems to be possible if I target the .NET Framework as opposed to .NET Core.

I don't need a report viewer I just need to render the results of an .rdlc report as a byte array.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Muaddib878
  • 336
  • 1
  • 4
  • 11
  • 1
    https://learn.microsoft.com/en-us/sql/reporting-services/report-server-web-service/accessing-the-soap-api?view=sql-server-2017 – Dale K Feb 28 '19 at 19:50
  • 1
    Thanks Dale - but this is for server reports (rdls). I would like to render local reports (rdlc) – Muaddib878 Mar 11 '19 at 21:44
  • 2
    To Downvoter: Why have you downvoted this? We use reporting extensively in our applications. I have done so with ASP.NET MVC 5 and ASP. NET Core 2.0 referencing the .NET Framework. Are you saying RDLCs are deprecated and there is a better solution?? – Muaddib878 Mar 11 '19 at 21:46
  • Is this relevant https://stackoverflow.com/questions/49309797/rdlc-local-report-viewer-for-asp-net-core-and-angular2-0 – Dale K Mar 11 '19 at 21:59
  • 1
    Not sure. "Don’t yet have timeframes to share" for Forerunner Software. And regarding the OP's solution: he gives no indication to what libs he's referencing on the server. I suspect he's referencing .NET Framework from his ASP. NET core solution. I would like to know if this is possible referencing .NET Core (especially since ASP .NET core 3 will no longer support .NET Framework) – Muaddib878 Mar 11 '19 at 23:06
  • It seems the only way forward is to use server hosted .rdl reports on SSRS. Microsoft appears to be ignoring the existence of .rdlc entirely with respect to ASP. NET core – Muaddib878 Mar 13 '19 at 18:31
  • 1
    I have used AspNetCore.Reporting library to do this. I have written a article on how you can do this. Check the link below. http://blog.geveo.com/IntegratingRDLCReportsToNetCoreProjects – Tharindu Jayasinghe Aug 11 '20 at 15:35

5 Answers5

10

If you want to create pdf/excel/word using rdlc report I recommend you can use AspNetCore.Reporting library. This is open source and comes as a nuget package. you can integrate this in your .NET Core API or .NET Core Azure function. You can generate a byte array convert it to base 64 string and retrieve that to your client side. More on the link in the comment.

Tharindu Jayasinghe
  • 2,821
  • 1
  • 15
  • 15
  • 1
    more details on this... http://blog.geveo.com/IntegratingRDLCReportsToNetCoreProjects – Tharindu Jayasinghe Aug 12 '20 at 00:27
  • Hi @Sras, did you follow the article? what's the issue you get ? We are successfully using this for one of our live systems which generates nearly 6 different reports. – Tharindu Jayasinghe Sep 10 '20 at 02:47
  • 2
    I have created a project in github. you can find the link here. https://github.com/tharindubuddhi/netcorerdlc – Tharindu Jayasinghe Oct 07 '20 at 07:44
  • issue binding the datasource. it keeps loading. and error. I am using Core 3.1 – Sras Oct 08 '20 at 03:29
  • when creating rdlc report – Sras Oct 08 '20 at 06:58
  • the problem is using VS code on Mac. I try running on windows working fine..... I need to change "\\" to "/" on Mac. but this appears "Unable to load shared library 'kernel32.dll' or one of its dependencies" – Sras Oct 08 '20 at 08:58
  • Does this library support subreports? – Hrvoje Batrnek Nov 17 '20 at 03:55
  • No I don't think so. I haven't tried it. Even the rdlc designer don't show the sub reports components. – Tharindu Jayasinghe Nov 17 '20 at 11:09
  • any update about the rdlc report on macbook – Sras Feb 16 '21 at 09:10
  • AspNetCore.Reporting will work, however it has a plenty of limitations (you can't add external images using URLs, also you can't add a normal link in your report) issue created https://github.com/amh1979/AspNetCore.Reporting/issues/20 – Mahmoud Hboubati Sep 12 '21 at 08:59
  • the AspNetCore.Reporting library have some cashing issues if you use parameters, the first report will be generated fine (and any report with same parameters), however if you run a report with different parameters you'll either get an error or the report will be generated with mix data). the library didn't receive any update or fixes since 2018 so I wouldn't recommend it if you have 2 or more reports with different parameters – vega_gf Oct 01 '21 at 10:45
2

You very well can render rdlc into a byte array. Please see a related question I asked a while back. RDLC Local report viewer for ASP.NET Core and Angular(>2.0).

Eventually a creative discussion on that thread resulted in an angular package(https://www.npmjs.com/package/ng2-pdfjs-viewer - Disclosure; I am the author) with consumable rdlc byte array functionality on client side. Of course, instead of this package, you may choose another javascript library to display the byte array.

A simple usage on angular would be like this. Please note, most of the code can be reused even if you are using plain js or another framework.

The below code demonstrates

1. Spitting byte array using RDLC report viewer control on aspnet core action method(on server side) and sending it over wire using http. (Code is in C#)
2. Processing response's byte array into a blob object (Js)
3. Feeding blob object into ng2-pdfjs-viewer.
4. ng2-pdfjs-viewer internally uses Mozilla's PDFJS to accomplish the feat of displaying the PDF on browser.
(FYI.. I took code from samples provided on ng2-pdfjs-viewer package. Replace step 3 and 4 if you are using another library or plain javascript)

<!-- your.component.html -->
<button (click)="showPdf();">Show</button>
<div style="width: 800px; height: 400px">
  <ng2-pdfjs-viewer #pdfViewer></ng2-pdfjs-viewer>
</div>

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 showPdf() {
    let url = "http://localhost/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")
}
int-i
  • 661
  • 1
  • 12
  • 28
  • 2
    No - please reread the question. In order to get the "ReportViewer" and "LocalReport" classes I must target the .NET Framework. These classes are NOT supported on .NET Core. ASP .NET Core 3 will only run on .NET Core - unlike ASP .NET Core 2 which gives you the option of referencing the .NET Framework. – Muaddib878 Jul 02 '19 at 20:00
  • Thanks for pointing it out. I haven't upgraded to aspnet core 3 yet. Didn't know they removed one useful feature altogether. – int-i Jul 05 '19 at 18:26
  • @Muaddib878 I do not see they mention this feature on migration guide. Try editing core project file and directly reference dll like this. See if it accepts it ` path\to\MyAssembly.dll ` – int-i Jul 09 '19 at 13:43
  • int-i: It's not that they've removed this feature - it's never been present for .NET Core. ASP .NET Core 2.0 gives you the option of referencing the full .NET Framework (which supports RDLC) or .NET core (which does not support RDLC) . Now, ASP .NET Core 3 will ONLY allow you to target .NET Core - which currently does not support RDLC – Muaddib878 Jul 09 '19 at 20:52
  • 1
    int-i: The current report viewer dlls rely on classes in the full .NET Framework - referencing the dlls as you suggest will not work if you are using .NET Core – Muaddib878 Jul 09 '19 at 20:55
  • @Muaddib878 Referencing Full .net dlls was a feature added in core 2.0(Which allowed developers to use 3rd party dlls and didn't needed to recompile them), which was not present in earlier versions. You may contact microsoft, and create an github issue to track it. – int-i Jul 10 '19 at 19:37
  • ASP .NET Core 1.x was also able to reference the full .NET Framework. This was always the case with ASP .NET Core, but starting with ASP .NET Core 3.0 you can no longer reference the full .NET Framework. – Muaddib878 Aug 09 '19 at 23:06
  • Anyway, the only way to currently render client RDLC reports with .NET core (w/o the full .NET Framework) is to use the paid Syncfusion solution. I have tested the trail version and it works well. It is also possible to render server hosted RDL reports with ASP .NET Core (without any 3rd party tools) - not ideal however as I would have to migrate many RDLC reports to RDL – Muaddib878 Aug 09 '19 at 23:08
1

In case anyone is still looking for a similar solution, I would recommend using "ReportViewerCore.NETCore".

Here is the nuGet reference - https://www.nuget.org/packages/ReportViewerCore.NETCore/

Here is the github link to the repo - https://github.com/lkosson/reportviewercore/

Basic usage

Stream reportDefinition; // your RDLC from file or resource
IEnumerable dataSource; // your datasource for the report

LocalReport report = new LocalReport();
report.LoadReportDefinition(reportDefinition);
report.DataSources.Add(new ReportDataSource("source", dataSource));
report.SetParameters(new[] { new ReportParameter("Parameter1", "Parameter value") });
byte[] pdf = report.Render("PDF");
Its BK
  • 26
  • 3
0

You can not render .rdlc reports in .NET Core, using .rdlc as a byte array.

Alan Turing
  • 2,482
  • 17
  • 20
0

Rendering RDLC reports relies on WinForms and WebForms and is currently only supported on .NET Framework. Hopefully Microsoft will make a (slimmed down) version available (just rendering the reports for starters) on .NET Core or .NET 5, but no word as of yet.

As an alternative, you could go for a solution where you run report rendering as a separate ASP.NET 2 app targeting .NET Framework, while the rest of your app could target .NET Core 3 or later. That way, you can call the reporting endpoints with the appropriate data, and it returns a rendered report.

This is what I've done, creating a sort of microservices architecture where multiple .Net Core 3.1 apps can post both the XML RDLC report definition and data to an endpoint running on net48, which uses the LocalReport class to render the report to the desired format, returning it as a byte array.

Angular app |  ---->  |  APIs (.Net Core 3.1)  |  ---->  |  API (.Net Framework 4.8)
Knelis
  • 6,782
  • 2
  • 34
  • 54
  • I can use on Windows ... but on Mac having. Unable to load shared library 'kernel32.dll' or one of its dependencies – Sras Oct 08 '20 at 09:30