3

i am stuck and Please help me with to bind the Image in dynamically in RDLC report Web API core3.1 application, i set image "external" image but when i bind image getting error "EnableExternalImages property has not been set for this report." please help me.report generating fine.

Dictionary<string, string> parameters = new Dictionary<string, string>();
        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        Encoding.GetEncoding("windows-1252");
        //LocalReport report = new LocalReport("Report3.rdlc");
        LocalReport report = new LocalReport("Report3.rdlc");
        parameters.Add("Image", @"file:///E:\\DemoRDLC2\\DemoRDLC2\\DemoRDLC2/FileImage/Car.PNG");
        var result = report.Execute(GetRenderType("pdf"), 1, parameters);
        return result.MainStream;

enter image description here

  • did you enable LocalReport.EnableExternalImages = true; for the ReportViewer? – NajiMakhoul Oct 24 '20 at 08:04
  • Hi NajiMakhoul,thanks for reply but we are work in core API application and we have not "ReportViewer" library because we can't use web form in API core application.this above code is working file with when set as "Embedded" source. – user11754632 Oct 24 '20 at 08:25
  • try to add image in memoryStream something like the answer here : https://stackoverflow.com/questions/44694032/using-a-resource-image-as-the-value-in-rdlc-parameter – NajiMakhoul Oct 24 '20 at 08:29
  • Hi NajiMakhoul, i have tried what you suggested but getting error "Could not find the resource "AspNetCore.ReportingServices.Rendering.HPBProcessing.Images.resources" help me. problem with bind image dynamically. – user11754632 Oct 24 '20 at 10:20

2 Answers2

2

i tested it and it's works, here is my code :

first of all ,convert your image to base64string

string paramValue = "";
using (var b = new Bitmap(@"YOUR IMAGE")){
     using (var ms = new MemoryStream()){
         b.Save(ms, ImageFormat.Bmp);
         paramValue = Convert.ToBase64String(ms.ToArray());
       }
    }

then add Base64String value to your parameters dictionary:

parameters.Add("Key1", "value1");
parameters.Add("Key2", "value2");
parameters.Add("image", paramValue);

RDLC image propertise: enter image description here

PDF file Result:

enter image description here

NajiMakhoul
  • 1,623
  • 2
  • 16
  • 30
0

I just got it. I use Microsoft.ReportViewer.NetCore

The image has to be tif or eml. I have used tif.

Read this link: https://github.com/lkosson/reportviewercore#supported-rendering-formats

This is the code to print in a new page, from the sample in github:

        private IActionResult PrepareReport(string renderFormat, string extension, string mimeType)
    {
        string pathRdlc = $"{this._env.ContentRootPath}\\Reports\\Report.rdlc";
        string pathPhoto = new Uri($"{this._env.WebRootPath}\\Photos\\Photo1.tif").AbsoluteUri;

        using var report = new LocalReport();

        var parameters = new[] { new ReportParameter("pPhoto", pathPhoto) };

        byte[] fileBytes = System.IO.File.ReadAllBytes(pathRdlc);
        MemoryStream rs = new MemoryStream(fileBytes);

        report.EnableExternalImages = true;
        report.LoadReportDefinition(rs);
        report.SetParameters(parameters);

        var rpt = report.Render(renderFormat);
        return File(rpt, mimeType);
    }

To download file do this: return File(rpt, mimeType, FileName + extension);

I hope I've helped

Federico
  • 81
  • 2
  • 7