1

I am using reporting package - AspNetCore.Reporting -2.1.0. I want to print my RDLC report having an external image. During rendering to pdf an error occurred.

An error occurred during local report processing.;Report 'Payslip' contains external images. The EnableExternalImages property has not been set for this report.

Rendering part of my code:

string reportFileName = "Payslip.rdlc";
if (paySlip.IsHourlySalary)
    reportFileName = "Payslip.rdlc";
else
{
    reportFileName = "PaySlipForAnnual.rdlc";
}
string ReportPath;
if (_webHostEnvironment != null)
    ReportPath = Path.Combine(_webHostEnvironment.ContentRootPath + "\\TMReports", reportFileName);
else
{
    ReportPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "/TMReports", reportFileName);
}
LocalReport localReport = new LocalReport(ReportPath);

message += " Before localReport.SetParameters(param);";
message += " Before localReport.DataSources.Add(cd);";
localReport.AddDataSource("dsPaySlip", dtPaySlip); // Add  datasource here    

message += " Before  byte[] bytes = localReport.Render(";
var result = localReport.Execute(RenderType.Pdf, 1, reportParams, mimeType);
               
return result.MainStream;

1 Answer 1

6

Run this before Rendering

localReport.EnableExternalImages = true;

Edit:

Seems the open source library you are using does not expose the variable nor the method you need.

enter image description here

But the methods are there in a private variable of the sealed class.

AspNetCore.Reporting Lib

So you can still change it's value by reflection...

It's not pretty but it will get the job done.

AspNetCore.Reporting.LocalReport rpt = new AspNetCore.Reporting.LocalReport(yourReportPath);
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
FieldInfo field = rpt.GetType().GetField("localReport", bindFlags);
object rptObj = field.GetValue(rpt);
Type type = rptObj.GetType();
PropertyInfo pi = type.GetProperty("EnableExternalImages");
pi.SetValue(rptObj, true, null);
5
  • It is not possible to set in asp.net core 5. It is possible for older asp.net reporting services. Apr 21, 2021 at 10:25
  • My bad. But the method seems to be still publicly accessible, you may need to create your own LocalReport class by extending AspNetCore.Reporting.LocalReport. If you need example code, please give me time. Apr 22, 2021 at 2:10
  • @NandanKumarDas Does the updated answer works for you? Apr 28, 2021 at 6:19
  • 2
    i used in .net5 class library, and worked.
    – Cem
    Nov 12, 2021 at 11:03
  • 1
    for me also worked with dotnet 6. thanks Oct 7 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.