External images in .rdlc data reports for winforms

2020-07-27 17:40发布

问题:

I searched Google for days to show images on .rdlc datareports but still not found a solution.
I have set:
reportViewer1.LocalReport.EnableExternalImages = true;
Image properties to "External" and have set parameters value to the value property.

 ReportParameter Path;
        Path = new ReportParameter("Path", "C:\\Test\\579569.png");
        this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { Path });  

But still i get a broken image. Is there something i am missing.I am trying this in WinForms. I know this question is asked by others..but i didn't get the result that i wanted.

Thanks in advance

回答1:

The image url must be using format file:////F:\111\333.JPG



回答2:

@Praveen is right. I used Server.MapPath to get the physical path of the image:

"file:///" + Server.MapPath("~/images/nokia.jpg")

and then I set reportViewer1.LocalReport.EnableExternalImages = true; as well.



回答3:

Your paths in an RDLC have to be URIs, then the string you pass to the ReportParameter is the AbsolutePath (in your case file:///C:/Test/579569.png)

    Dim filepath As Uri
    filepath = New Uri("C:\Test\579569.png")

    Dim Path As ReportParameter
    Path = New ReportParameter("Path", filepath.AbsolutePath)

    Me.reportViewer1.LocalReport.SetParameters(New ReportParameter() {Path})

Excuse VB.Net code but you get the idea.



回答4:

Have you tried setting MIME Type property to ImageControl in the rdlc file?



回答5:

Firstly, you take a new Form in your project on Load event you Wright this line below:

reportViewer1.LocalReport.EnableExternalImages = true;

after that take reportViewer on that page and set smart tag of that, choose Design a new report and take an image control on it from ToolBox, set its property

Source = External

Value = file:\D:Images\Sunset.jpg

Note: Image(Sunset.jpg) saved in Images folder on D drive. You changed it according to your requirement.