Reputation: 21
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
Upvotes: 2
Views: 17619
Reputation: 1
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;
Upvotes: 0
Reputation: 81
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)
});
Upvotes: 0
Reputation: 41
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.
Upvotes: 0
Reputation: 1842
@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.
Upvotes: 5
Reputation: 6240
Have you tried setting MIME Type property to ImageControl in the rdlc file?
Upvotes: 0
Reputation: 16003
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.
Upvotes: 1