1

I heard of rendering RDLC being impossible (or not easy) in aspnet core 2.

Is it possible to render an RDLC as PDF or Excel in Aspnet Core 3.0 or 3.1 ?

PS: But I have a working code in Aspnet MVC 5 targeting .Net Framework.

Bellash
  • 7,560
  • 6
  • 53
  • 86
  • Do you have a webapplication asp netcore? – Julián Oct 18 '20 at 17:31
  • I am not a Net Core developer but I have worked with ASP .NET Framework and RDLC, Net Core is a technology that in my humble opinion is in its infancy, If you want to use the classic Winforms ReportViewer in your web application I think it is not possible, I tried implement this solution (the purpose is to generate the PDF file in a folder), but Miscrosoft .ReportViewer.Winforms is not supported by NetCore, its implementation I think is under discussion: https://stackoverflow.com/questions/35890414/can-one-use-reportviewer-control-in-asp-net-core – Julián Oct 19 '20 at 00:13

1 Answers1

0

Found a solution and I post this for using the following packages

<PackageReference Include="AspNetCore.Reporting" Version="2.1.0" /> 
<PackageReference Include="System.CodeDom" Version="4.7.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" />

but still, for the report designer to work, I had to create an .net standard library project, where I added the .rdcl file for design purpose.

After that I moved final file a Reports directory (not inside wwwroot) and I could be able to generate a PDF file using the following code (in asp.net core 3.1)

    string rdlcFilePath = Path.Combine(hostEnvironment.ContentRootPath, 
          "Reports", "UserDetails.rdlc");
        // return Ok(rdlcFilePath);
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        Encoding.GetEncoding("windows-1252");
        LocalReport report = new LocalReport(rdlcFilePath);

        List<UserDto> userList = getUserList;
        report.AddDataSource("dsUsers", userList);
        var result = report.Execute(GetRenderType("pdf"), 1, parameters);
        return File(result.MainStream, 
               System.Net.Mime.MediaTypeNames.Application.Octet,
               "users.pdf");

Now you can put an href to a element to download the file or you can receive it as a blob if you want inside your angular service.

Thank you!

Bellash
  • 7,560
  • 6
  • 53
  • 86