问题
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.
回答1:
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:
- 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.
- Setup a virtual directory on the default web site in the local SSRS machine IIS Manager.
- 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
- Voila, it works… or at least it worked for me.
回答2:
Have you tried using a fully qualified path?
http://<servername>/images/image1.jpg
More Info
回答3:
I have this problem too..
I have looked at the SSRS error logs, and the IIS server logs. Some findings:
- External images with URLs to static images work. (e.g. http://intranet/site/logo.jpg)
- 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 ?.
- 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.
- IIS logs show the report server requesting the image, and getting a 200 OK response.
- 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.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.
回答4:
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
来源:https://stackoverflow.com/questions/1834305/how-to-add-an-image-to-an-ssrs-report-with-a-dynamic-url