question

NoelZike-4026 avatar image
0 Votes"
NoelZike-4026 asked YijingSun-MSFT answered

Trouble displaying images in RDLC reports dynamically

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


dotnet-aspnet-webforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered

Hi @NoelZike-4026,

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://docs.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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.