In this example I will explain how we can use external images in .rdlc reports.
Create a Web Application.
Right click on Project in Solution Explorer –> Add New Item – Select a .rdlc Report
Now Drag and Drop a image control in Header section in the Report.rdlc
Go to Report Menu in Visual Studio and Select Report Parameters –> and Add a parameter with name Path
Now we will set this path parameter to our image’s value property and provide the value at run time, select image and properties(F4) and set following values to Source and Value properties
Source = External and Value = !Path.value
Now create a Image folder in your solution and Add some images to that folder.
As I am only concentration on showing images on the report in this example I am not loading any data on to the report.
Now open Default.aspx page and add MicrosoftReportViewer Control and set MicrosoftReportViewer control source to Report1.rdlc
Now we are ready with design part,
One of the most important thing while displaying external images is to set EnableExternalImages perperty of MicrosoftReportViewer.LocalReport’s to True, this will allow us to show external images on the .rdlc reports
And also we need to set the Path parameter value so that image will be displayed on the report for that we need to all following code to Page_Load event
Now we are ready with our code, just build and run and test
Hope this helps.
Tags : .rdlc report, external Images, ASP.NET
Thanks for this article it solved one of my problems.
ReplyDeletePerhaps you might be able to help me with my other problem. How would I go about loading an unspecified amount of external images into a report from a folder on the web server?
You can add images dynamically to Report View control not to the Local Report following code will add image to report viewer
ReplyDeleteimg.ImageUrl = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "")
+ @"/Images/Report.jpg";
ReportViewer1.Page.Header.Controls.Add(img);
please let me know if it helped you.
Hi,
ReplyDeleteI have tried the code but i am getting the following error.
The Hidden expression used in image ‘image1’ returned a data type that is not valid.
Please let me know what i am missing.
Actually I have created img as Image object which is System.Web.UI.WebControl.Image type please find the code which might help you, I didnt add any control at design time here I am creating control also at run time.
ReplyDeleteImage img = new Image();
img.ImageUrl = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath, "")
+ @"/Images/Report.jpg";
ReportViewer1.Page.Header.Controls.Add(img);
Regards,
satish.
Gracias por este blog, tu explicación es muy buena... (gmmarcos@hotmail.com)
ReplyDeleteSaludos!
Thanks Marcos, I didnt understand Spanish, however I had converted into English using Google Converter.
ReplyDeleteThanks for your appreciation.
Regards,
Satish.
Hi,
ReplyDeleteI need a help in binding object to a .rdlc file.
Actually My object contains one more object inside and a list of anothere object.
Normal propertis of ihe object i can be able to bind and show in .rdl file.but the object and collection i cant be able to bind
Need some assistance on that
Stis this also not dispaly image. n if display then it is not coming in pdf formate. so....... plz help
ReplyDeleteu can set image as Embeded go throught following
ReplyDeleteRight click on Project in Solution Explorer –> Add New Item – Select a .rdlc Report
then take image from toolbox then
Go to Report Menu in Visual Studio and Select -->Embedded Image then select image whatever u want then give o.k
then press f4 and give Source -- Embedded and
in value pramater select image name which u give in Embedded image. then u get image in your report
How to get this if it is for windows application
ReplyDeletehi,i am new to this blogs,i have developed RDLC Reports,
ReplyDeletei have developed Charts type is line,age on x axis and weight on y-aixs we have one age column and many weight columns,reports is completed,i want to show one text lik (p1 weigh)like for all weight,how i can show one fixed text on line,i think iots on like Datapoint,how i show i text on one line,different text on different lines,or how i show one text one data point in one line,by using datapoint it can repeated,cann i show data point once only in rdlc reports
if any one knows pls send your reply to plhk26@gmail.com
Thank you working very well
ReplyDeletevery very thanks .....
ReplyDeleteHello,
ReplyDeleteI am new to these blogs. I am editing a report creating by a third party. It seems like the header of the report that has a table in the body has an embedded image as the table header. I've added some new items in the table and now need to edit this header to add the column name. I am unable to locate this image in the project. It has the following properties:
MimeType = image/jpeg
source = embedded
name = report1Header
Any ideas how I can accomplish this?
Thanks.
Hi. I have did the following code but it is showing a broken image icon. the image i wanted to display is not showing.
ReplyDeletemy code is to generate the report and image when user click on the button. I have put the code under the button click part.
This comment has been removed by the author.
ReplyDeleteI have written the below code in VB.Net.
ReplyDeleteImage is not shown on the report control
Dim rds As New ReportDataSource("Reports", DataSetDS)
_newObjReport.LocalReport.DataSources.Clear()
_newObjReport.LocalReport.DataSources.Add(rds)
PlaceHolderReport.Controls.Add(_newObjReport)
_newObjReport.LocalReport.EnableExternalImages = True
Dim param1 As List(Of ReportParameter) = New List(Of ReportParameter)
param1.Add(New ReportParameter("HeaderImagepath", "_folder1/images/image.jpg"))
_newObjReport.LocalReport.SetParameters(param1)
_newObjReport.LocalReport.Refresh()
please suggest.
Thanking you.
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.
ReplyDeleteHi,I have tried given steps,getting "The Value expression for the image ‘image1’ is invalid (it is an empty string)." error,Please suggest
ReplyDeleteyou double click the paramater then clikc ok
DeleteHi i have also tried given step bt image is not displaying and my code is
ReplyDeletePlease suggest the essues in my code
con = new SqlConnection(strCon);
cmd = new SqlCommand("rdlsTest", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@RID", RqstID);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
ReportDataSource[] rds = new ReportDataSource[3];
rds[0] = new ReportDataSource("DataSet1_rdlsTest", ds.Tables[0]);
ReportDataSource rds1 = new ReportDataSource("DataSet1_DataTable1", ds.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds1);
ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
ReportViewer1.LocalReport.EnableExternalImages = true;
ReportParameter[] parameters = new ReportParameter[1];
List param1 = new List();
param1.Add(new ReportParameter("Path",Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath,"")+@"/Images/gov.gif"));
ReportViewer1.LocalReport.SetParameters(param1);
ReportViewer1.LocalReport.Refresh();
sir image not showing there a "X" Printed what i do
ReplyDeleteCommand
ReplyDeletestring path = Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath,"")+@"/Images/gov.gif";
is very nice.
If You have AbsoluteUri with parameters, (e.g. http://localhost:56595/Default.aspx?hqsdf=znstryh5ki2ydjo2oobesqr3 ), You are with this command in hell.
Imho better is this variant:
string path = Request.Url.AbsoluteUri.Substring(0,Request.Url.AbsoluteUri.IndexOf('?')).Replace(Request.Url.AbsolutePath,"") + @"/Images/gov.gif";