Trouble displaying images in RDLC reports dynamically

Noel Zike 1 Reputation point
2020-12-15T13:36:27.153+00:00

I have an asp.net web application that I am having a problem loading images into rdlc reports. I have scoured the internet and have tried a lot of the suggestions and still am stuck. I would appreciate some assistance. I am using VS 2013 Ultimate.

In my project there is a folder called Photos which currently contain about 4,000 images. These photos are not in the database. When I create my report using the report wizard, I use view in sql server 2016 to pull applicable records, let's just say I pull Name, and Photo. The names would be strings, "Wanda", "Mike" and the photos are the relative path to the project: "~/Photos/Wanda.jpg" and "~/Photos/Mike.png". NOTE, some aer jpg, some jpeg, and some png files. So when my report displays I have a field for Fields!Name.Value and one for Fields!Photos.Value. Names display but not the photos, just their text path. I then inserted an Image tool from the toolbox into a Text box on the report, and marked it as External in type, and set the value of the image to Fields!Photos.Value. The code behind the report located in the webpage holding the report viewer looks like this:

                ReportViewer1.LocalReport.EnableExternalImages = true;
                ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", ObjectDataSource2));
                ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
                ReportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc";
                ReportViewer1.LocalReport.Refresh();
                ReportViewer1.Focus();

When the report is run, all the selected names appear but not the pictures. I ran across a nice example by this gentleman:

https://www.aspsnippets.com/Articles/Dynamically-add-and-display-external-Image-in-RDLC-Report-from-code-behind-in-ASPNet.aspx

Which seems to be the best one so far, but I do not wish to copy all my photos again to the Report1.rdlc report data images file. I want to keep them where they are. What must I do to load and display the images and to ensure the Mime type of each is set correctly for the display?

If this is not the correct forum please be kind enough to direct me to the correct one.

Thanks in advance.

Noel

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,066 Reputation points
    2020-12-17T07:40:11.253+00:00

    Hi @Noel Zike ,

    Accroding to your description, I suggest you could create a dataset and use processingmode property.

    Just like this:

    DataSet ds;  
    ReportDataSource datas = new ReportDataSource("ds_", ds.Table(0));  
    ReportView1.ProcessingMode = Microsoft.Reporting.WebForm.ProcessingMode.Local;  
    ReportView1.LocalReport.DataSources.Add(datas);  
    this.ReportView1.Refresh();  
    

    More details,you could refer to below articles:

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.reporting.webforms.reportviewer.processingmode?view=sqlserver-2016
    https://www.codeproject.com/Questions/201040/how-to-set-images-dynamically-in-rdlc-Report-Viewe


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Yijing Sun

    0 comments No comments