I’d like to load image(s) at runtime (dynamically) into my report (inside the header).
I’ve already create the following parameter:
Name: Path
Datatype: String (should be the path to the image)
Allow Blank = True
Then I’ve draged and droped an image control to my report.
Set the name to: Image2
Imagesource: External
Use the following image: [@Path]
Now (back in my MainWindow) I’ve added the following code:
viewerInstance.LocalReport.EnableExternalImages = true;
List<ReportParameter> param1 = new List<ReportParameter>();
//header_2.png exists (for test purposes) in the root folder
param1.Add(new ReportParameter("Path", @"/header_2.png"));
viewerInstance.LocalReport.SetParameters(param1);
It doesn’t work.
I’ll get this error message:
The invocation of the constructor on type ‘ReportViewer.MainWindow’ that matches the specified binding constraints threw an exception.
{“The source of the report definition has not been specified”}
Any ideas?
I am not very sure about how to do it with External Images using the absolute path in SSRS 2008. But I guess I can provide with a workaround but this would work only in case you have all the images that you would be using in reports available to you beforehand.
You can add an Image control to the report. In the Image Control property, provide name, select the image source as Embedded, and click on Import, and select the image. Click Import. The image is imported. Now you can import all images like this. Once done, go to Image control property again and set the Use this Image as “[@Path]”. Now you do not need to pass the absolute path but only the image name amongst the imported images which you can see under images in Report Data.
Also, if you want to use External Images, as per this msdn article you need to provide the Url for the image and not the absolute path. In this case you can hoist your image on a server and pass the path in the Path parameter. Select the image source as External. I have tested this and it works.
Edit: You can also upload the images to the ReportServer through the Report Manager and provide the path to that image as the relative path in the RDL after you specify the Image Source as external. e.g. /Report/Logo.png. You can also upload multiple images and use them by providing the path as parameter to the report.