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