How to add an image to an SSRS report with a dynamic url?
Asked Answered
H

4

15

I'm trying to add an image to a report. The image src url is an IHttpHandler that takes a few query string parameters. Here's an example:

<img src="Image.ashx?item=1234567890&lot=asdf&width=50" alt=""/>

I added an Image to a cell and then set Source to External and Value to the following expression:

="Image.ashx?item="+Fields!ItemID.Value+"&lot="+Fields!LotID.Value+"&width=50"

But when I view the report, it renders the image html as:

<IMG SRC="" />

What am I missing?

Update

Even if I set Value to "image.jpg" it still renders an empty src attribute. I'm not sure if it makes a difference, but I'm using this with a VS 2008 ReportViewer control in Remote processing mode.

Update

I was able to get the images to display in the Report Designer (VS 2005) with an absolute path (http://server/path/to/http/handler). But they didn't display on the Report Manager website. I even set up an Unattended Execution Account that has access to the external URLs.

Hasidism answered 2/12, 2009 at 16:58 Comment(4)
If you add a new text box on the report and get it to display the result of the same expression (online debugging!!) what does it show?Lapel
Good idea, but it displays the correct url.Hasidism
Are ssrs and iis for the image on the same box?Bield
No, the images are on a separate web server.Hasidism
C
4

I have a SSRS Report that displays the information about the countries of the users of a site that we support at work. This is based on the IIS log data. On this report, in the first column of the table is an image field that holds a small .gif of the flag for each country. I was running into the same exact issue described in the question above. The path to the external image was calculated in the report’s query based on the country code. I initially setup the URL to point to something like http://www.mystaticcontent.com/fotwimg/us.gif for a United States flag and so forth. All I got was a red X broken image displayed in the report. Then I found this MSDN article that shined some light on the issue for me.

This is what I did with the report to make it work:

  1. Moved the fotwimg folder that has all the gifs from the static content server to the local SSRS machine, which also has a web server running on it.
  2. Setup a virtual directory on the default web site in the local SSRS machine IIS Manager.
  3. Then I changed the report query to refer to the image in the local SSRS machine, by machine name, like this http://mylocalssrsmachine/fotwimg/us.gif
  4. Voila, it works… or at least it worked for me.
Circumscription answered 26/3, 2010 at 4:18 Comment(2)
Thanks for the answer! I was trying to avoid putting the images on the report server. I wanted to display thumbnails that linked to the full size images, but I ended up using the hyperlink action on a normal text field instead. I'll have to remember this for the next time it comes up.Hasidism
In SQL Server 2008, Report Server no longer uses IIS. Do you guys know how/where to install the images on the report server?Rod
B
2

Have you tried using a fully qualified path?

http://<servername>/images/image1.jpg

More Info

Bield answered 2/12, 2009 at 23:16 Comment(1)
Yes, I was able to get the images to display in the Report Designer (VS 2005) with an absolute path. But they didn't display on the Report Manager website.Hasidism
B
2

I have this problem too..

I have looked at the SSRS error logs, and the IIS server logs. Some findings:

  1. External images with URLs to static images work. (e.g. http://intranet/site/logo.jpg)
  2. I can add parameters to static image URLs and it still works. (e.g. http://intranet/site/logo.jpg?foo=1) The parameter will be ignored, and the image displays. This suggests that SSRS is not choking on the ?.
  3. If I link the external image to an ASPX page that returns a report with no parameters (e.g. http://intranet/site/image.aspx), it still doesn't work.
  4. IIS logs show the report server requesting the image, and getting a 200 OK response.
  5. Report server logs show this:

    webserver!ReportServer_0-116!14cc!01/09/2012-12:20:29:: i INFO: Processed report. Report='/Path/ReportName', Stream='' ui!ReportManager_0-115!7b8!01/09/2012-12:20:29:: Unhandled exception: System.Web.HttpException: File does not exist. at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
    at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I wonder if SSRS is doing something boneheaded like adding the "correct" file extension before saving the file?

i.e. something like (1) SSRS downloads /Page.aspx, which supplies an image with Content-Type: image/jpg; (2) SSRS saves this to a temporary folder with a filename like tempname.aspx.jpg; (3) SSRS looks for tempname.aspx to incorporate the image into the report; (4) Error

I suppose you could test this by handling .jpg requests in code-behind... Unfortunately that's beyond my ASPX skills at the moment.

Bathos answered 8/1, 2012 at 23:44 Comment(2)
did you ever get to find the solution to this? My external image has worked for 6 months. and now I get IMG tag onerror=this.errored=true; rrored="true"Jeanette
@Jeanette Sorry, no.Bathos
C
0

My case: Load from localhost depending on product's code.

Image.Source= "http://LOCALHOST/IMG/" + Fields!CODE.value + ".jpg"

Problem: Sometimes file is uploaded with extension ".png"; so it's needed a FileExists validation.

Solution: 1)Add auxiliar table

PRODUCT_PHOTO_EXTENSION

id (FK references PRODUCT) extension (varchar)

2)Create Store Procedure. Do the FileExists validation on sql and store the extension found in PRODUCT_PHOTO_EXTENSION.extension:

insert into PRODUCT_PHOTO_EXTENSION 
SELECT A.id,'.JPG' FROM PRODUCT A LEFT JOIN PRODUCT_PHOTO_EXTENSION AF ON A.id=AF.id WHERE AF.id IS NULL AND Matriz is null and dbo.FileExists('D:\directory\' + code + '.jpg')=1
 insert into PRODUCT_PHOTO_EXTENSION 
SELECT A.id,'.PNG' FROM PRODUCT A LEFT JOIN PRODUCT_PHOTO_EXTENSION AF ON A.id=AF.id WHERE AF.id IS NULL AND Matriz is null and dbo.FileExists('D:\directory\' + code + '.jpg')=1

3)Load image file using this field. (SSRS; image.source expression)

Iif(Fields!EXTENSION.Value<>"", "http://LOCALHOST/IMG/" & Fields!CODE.Value & Fields!EXTENSION.Value, "" )

4) Result: Load image according it extension; avoid that red "x".

Hope it helps

Commove answered 23/4, 2013 at 0:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.