none
External Images..

    Question

  • I am trying to add an external image to my .rdlc report in VS2005. I can add it by using a value expression of: ="file:///C:/Project/RTracker/Images/logo.gif"  but, this isn't accesptable once I delploy it. I cannot find ANYTHING on the web and have been looking for days!

    I have set my report viewer to this in my VB code for the web page:

    ReportViewer1.LocalReport.EnableExternalImages = True

    Then on my .rdlc report design, I want to use an image from my images directory in my project.

    Is there any code that I could put in the Report Code that would return the "URL" that I'm using and then use an expression for the image that ran the code?

    Like this for the code.. (although it doesn't work) 

    Function GetApplicationPath()
    Dim path As String = Left(Request.Url.AbsoluteUri, Request.Url.AbsoluteUri.Length + 1 - Request.Path.Length)
    Return path
    End Function

    Then for the Image, use the expression:

    =Code.GetApplicationPath() & "/logo.gif"

     

    Please any help would be appreciated.

    ~bg

    Saturday, April 29, 2006 2:51 PM

Answers

  • This has taken me the last couple of days as well and I would like to clarify the complete solution that worked for me. First, I passed a parameter to the reportviewer before refreshing the report. The parameter contains a path to the image file, which is located, normally, on the local hard drive. This parameter gets the path info from a combination of a my.setting and a string pulled from a field on the calling form. The end result is that a complete physical path is passed to the reportviewer before displaying the report. In this instance, I have a button event that sets up and opens the report. This is where I pass the parameter info. (the parameter acts more or less like passing a varible to the report).

     

    On the local report side (rdlc), I went to report/ report parameters and created a parameter names "P". I also placed the image control on the report and then set the 'value' of the image to:

     

    ="file:///" & Parameters!P.Value

     

    The ="file:///" part was the key to connecting to the local drive. Below is the code that is called before the report is opened.

     

    ReportViewer1.LocalReport.EnableExternalImages = True

    Dim params(0) As ReportParameter

    params(0) = New ReportParameter("P", My.Settings.PicturePath & "\" & Pic_NameTextBox.Text & Pic_FileTypeTextBox.Text)

    Me.ReportViewer1.LocalReport.SetParameters(params)

    ReportViewer1.RefreshReport()

     

    Note that the My.Settings.PicturePath simply contains the user's default image directory information. So, the report is passed a string like so: 'C:/Program Files/My Program/Pictures/Sunny Day.jpg'. 

     

    I hope that this helps someone having a hard time with this. It is really a fairly simple task that is not documented very well.

     

    Bob Ives

    Code Blue Designs

    Wednesday, September 12, 2007 3:49 AM
  • You can put the expression in a textbox to see the value it is generating and verify that it is the correct one.  Accessing the HttpRequest may not always work.  Report processing may happen in parallel on a background thread and therefore not be available.  As an alternative, you might consider passing in the base url as a hidden parameter to the report and referencing that parameter value in your expression.
    Tuesday, May 02, 2006 5:39 AM
    Moderator

All replies

  • You can put the expression in a textbox to see the value it is generating and verify that it is the correct one.  Accessing the HttpRequest may not always work.  Report processing may happen in parallel on a background thread and therefore not be available.  As an alternative, you might consider passing in the base url as a hidden parameter to the report and referencing that parameter value in your expression.
    Tuesday, May 02, 2006 5:39 AM
    Moderator
  • This has taken me the last couple of days as well and I would like to clarify the complete solution that worked for me. First, I passed a parameter to the reportviewer before refreshing the report. The parameter contains a path to the image file, which is located, normally, on the local hard drive. This parameter gets the path info from a combination of a my.setting and a string pulled from a field on the calling form. The end result is that a complete physical path is passed to the reportviewer before displaying the report. In this instance, I have a button event that sets up and opens the report. This is where I pass the parameter info. (the parameter acts more or less like passing a varible to the report).

     

    On the local report side (rdlc), I went to report/ report parameters and created a parameter names "P". I also placed the image control on the report and then set the 'value' of the image to:

     

    ="file:///" & Parameters!P.Value

     

    The ="file:///" part was the key to connecting to the local drive. Below is the code that is called before the report is opened.

     

    ReportViewer1.LocalReport.EnableExternalImages = True

    Dim params(0) As ReportParameter

    params(0) = New ReportParameter("P", My.Settings.PicturePath & "\" & Pic_NameTextBox.Text & Pic_FileTypeTextBox.Text)

    Me.ReportViewer1.LocalReport.SetParameters(params)

    ReportViewer1.RefreshReport()

     

    Note that the My.Settings.PicturePath simply contains the user's default image directory information. So, the report is passed a string like so: 'C:/Program Files/My Program/Pictures/Sunny Day.jpg'. 

     

    I hope that this helps someone having a hard time with this. It is really a fairly simple task that is not documented very well.

     

    Bob Ives

    Code Blue Designs

    Wednesday, September 12, 2007 3:49 AM
  • Hi, Just do one thing......... when u retrieve data from ur database server & fill the datatable......

    then .. in very next step...

    'dtbl' is the datatable
    ---------------------------------------------
     foreach (DataRow dr in dtbl.Rows)
                {
                    dr["ImagePath"] = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Length + 1 - Request.Path.Length) + "ProjectName/Uploading/" + dr["ImagePath"];
                }
    -------------------------------------------

    provide this above modified datatable to the report.

    as
    ImageControl's value

    =Fields!ImagePath.Value




    Have a nice time

    Deepak Anmol
    Sr Developer
    MCTS, MCP
    Tuesday, May 12, 2009 12:50 PM
  • I am trying to add an external image to my .rdlc report in VS2005. I can add it by using a value expression of: ="file:///C:/Project/RTracker/Images/logo.gif "  but, this isn't accesptable once I delploy it. I cannot find ANYTHING on the web and have been looking for days!

    I have set my report viewer to this in my VB code for the web page:

    ReportViewer1.LocalReport.EnableExternalImages = True

    Then on my .rdlc report design, I want to use an image from my images directory in my project.

    Is there any code that I could put in the Report Code that would return the "URL" that I'm using and then use an expression for the image that ran the code?

    Like this for the code.. (although it doesn't work) 

    Function GetApplicationPath()
    Dim path As String = Left(Request.Url.AbsoluteUri, Request.Url.AbsoluteUri.Length + 1 - Request.Path.Length)
    Return path
    End Function

    Then for the Image, use the expression:

    =Code.GetApplicationPath() & "/logo.gif"

     

    Please any help would be appreciated.

    ~bg

    Hi, Just do one thing......... when u retrieve data from ur database server & fill the datatable......

    then .. in very next step...

    'dtbl' is the datatable
    ---------------------------------------------
     foreach (DataRow dr in dtbl.Rows)
                {
                    dr["ImagePath"] = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Length + 1 - Request.Path.Length) + "ProjectName/Uploading/" + dr["ImagePath"];
                }
    -------------------------------------------

    provide this above modified datatable to the report.

    as
    ImageControl's value

    =Fields!ImagePath.Value




    Have a nice time

    Deepak Anmol
    Sr Developer
    MCTS, MCP
    Tuesday, May 12, 2009 12:51 PM
  • Ok..I have looked all over the internet and found different ways to do this External Image thing in rdlc reports.

    Nothing works.

    I have created the report with an Image, created the Parameter, set the Image value to the =file:/// & Parameter

    Then I passed the file path to the Report, but it still does not show the image.

      Me.ReportViewer1.LocalReport.EnableExternalImages = True
    
    
      Dim params(10) As ReportParameter
    
      params(0) = New ReportParameter("SellerName", "John Doe")
      params(1) = New ReportParameter("BuyerName", "Jane Doe")
      params(2) = New ReportParameter("IDImagePath", "c:\DriversLicense.bmp")
      params(3) = New ReportParameter("Make", "Cheverolet")
      params(4) = New ReportParameter("Model", "Impala")
      params(5) = New ReportParameter("Year", "2001")
      params(6) = New ReportParameter("VIN", "1Z6594JU665984")
      params(7) = New ReportParameter("SalePrice", "$600.00")
      params(8) = New ReportParameter("Day", Now().Day & GetOrdinal(Now().Day))
      params(9) = New ReportParameter("Month", MonthName(Now().Month))
      params(10) = New ReportParameter("DateYear", Now().Year)
    
    
      Me.ReportViewer1.LocalReport.SetParameters(params)
      Me.ReportViewer1.RefreshReport()
    

    Every Other parameter load and populates the correct textboxes except for the Image.

    I can static link the image.value field to the file:///c:\driverslicense.bmp file, and the picture loads in the designer, but does not show in the Reportviewer at runtime. 

    I can load the picture with the same link into a browser.  I just can't get the image to show in the ReportViewer.

    Help!

    Tuesday, May 04, 2010 3:10 AM
  • 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.


    Tuesday, January 25, 2011 9:28 AM
  • Thank you very much for posting this. I was looking for the solution for this problem for quite a while.

    It's amazing that it's not in the documentation on msdn.

    Friday, March 25, 2011 8:54 PM
  • I am getting following error at setparameters call. Please help.

    The source of the report definition has not been specified

    Wednesday, June 22, 2011 12:20 AM
  • you can just try in ur code file like this:

      ReportParameter[] parameters = new ReportParameter[1];

                parameters[0] = new ReportParameter("Image", @"file:\D:Images\icon.png");

    this worked for me

    • Proposed as answer by ranganayaki005 Wednesday, August 24, 2016 9:28 AM
    Friday, April 20, 2012 2:10 PM
  • You can put the expression in a textbox to see the value it is generating and verify that it is the correct one.  Accessing the HttpRequest may not always work.  Report processing may happen in parallel on a background thread and therefore not be available.  As an alternative, you might consider passing in the base url as a hidden parameter to the report and referencing that parameter value in your expression.
    Excelent
    Sunday, July 22, 2012 9:50 AM