External images in .rdlc data reports for winforms
Asked Answered
L

7

2

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

Linetta answered 15/1, 2010 at 9:0 Comment(0)
T
5

@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.

Transoceanic answered 3/3, 2011 at 19:54 Comment(0)
E
5

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

Ennead answered 15/2, 2012 at 8:18 Comment(0)
A
1

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.

Archaeology answered 20/1, 2010 at 19:1 Comment(1)
Actually, instead of filepath.AbsolutePath, you shoud use filepath.AbsoluteUri (at least for the latest report viewer)Slavocracy
V
0

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

Viridis answered 15/1, 2010 at 9:10 Comment(0)
M
0

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.

Machuca answered 24/1, 2011 at 12:45 Comment(0)
D
0

I got results using these codes in my own project

var imagePath = new Uri(HostingEnvironment.MapPath("PATH")).AbsoluteUri;
lr.ReportPath = HostingEnvironment.MapPath("/Report/Test1.rdlc");
lr.EnableExternalImages = true;
lr.SetParameters(new ReportParameter[] { 
    new ReportParameter("Path", imagePath)
});
Devorahdevore answered 26/6, 2022 at 8:11 Comment(0)
R
0

I know this is for an old post but it is still relevant now. I searched so much and most answers are for web sites. I was searching for c# reportviewer in a form and a local picture file.

It worked well using this:

Add the image in rdlc. set source to external set the value to File:\C:\MyPics\logo.png

if the path is stored in database, set the value to ="File:" +First(Fields!LogoFile.Value, "DataSet1")

I also added this code in my form (you can set it directly in reportviewer control's properties if you prefer) reportViewer1.LocalReport.EnableExternalImages = true;

Richter answered 7/10, 2022 at 3:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.