Setting image source in RDLC report dynamically
I was having the same problem, however the accepted solution didn't quite work for me. Turns out that I needed to set EnableExternalImages to true in addition to providing the path in URI format and setting my Image.Value to =Parameters!ReportLogo.Value
.
report.EnableExternalImages = true;
ReportParameter[] parameters = new ReportParameter[3];
...
Uri pathAsUri = new Uri(_info.LogoPath);
parameters[2] = new ReportParameter("ReportLogo", pathAsUri.AbsoluteUri);
report.SetParameters(parameters);
As there are no alternate (or any!) opinions on the matter, I've moved further along and have come up with a working solution.
I'm opting to create an on-demand file of the logo, storing it in a temp location. If the file doesn't exist, I'm creating it on the fly. If it does exist, I'm just referencing the image that does exist.
In the RDLC report, I've created a parameter called Path of type Text. Next, in the properties for the Image, I've changed the logo image from embedded to external and set "Use this image" to be the parameter: [@Path].
Then, in the code I'm passing in the file path as the Path parameter. But where I had previously gone wrong is that the path has to be a URL and I had been attempting to pass the location on disk. So, that portion should look like this:
ReportParameter paramLogo = new ReportParameter();
paramLogo.Name = "Path";
paramLogo.Values.Add(@"file:///C:\Users\Mike\AppData\Local\Temp\Logo.png");
reportViewer.LocalReport.SetParameters(paramLogo);
I will say that the MSDN documentation could be a little better. To their credit, there are many detailed documents about how to accomplish something at a higher level. This article helped. It clearly says that I needed a URL to the path, but it'd have been easier to examine that property directly in the library. However, finding the lower level documentation was harder and less fruitful. Here is the article for the Reporting Image object. There isn't much opportunity to set properties of interest.