![]() |
|
|
By: Sherlee Dizon | Read Comments (10) | Print Sherlee is an IT consultant and web application developer with over 14 years of experience as a software and web developer. Related Tips: More |
|
Companies often need to generate reports and forms from scanned images and various government supplied formats. Proper knowledge of how to incorporate images in a report is a must. I am new to SQL Server 2008 Reporting Services (SSRS) and Business Intelligence Development Studio and have been assigned to use these tools. I have used Crystal Reports as my reporting tool from my previous jobs, so I had some background in reporting, but needed to learn these new tools and features available in SSRS 2008. In preparation for this task, I tried to create a report where I need to display an images. When I saw the options for selecting the image source, a lot of questions came to my mind. When should I embed an image? Why should I use an external image instead of a database image source? What are the advantages and disadvantages when I use embedded, external or database as the image source? Take a look at this tip and I will share with you what I've learned.
An image is a report item that contains a reference to an image that is stored on the report server, embedded within the report, or stored in a database. An image can be a logo or picture that appears once on the report or it can be a picture that is repeated with rows of data. You can also use an image as a background for certain report items.
In SQL Server Reporting Services 2008 the image properties available are "Embedded", "External" and "Database". Let's dig into each of these options to learn about when we should use this option as well as the associated advantages and disadvantages.
Local report images are embedded in the report and then referenced. When you embed an image, Report Designer MIME-encodes the image and stores it as text in the report definition.
Most large sites uses the file system to store images. When you use an external image in a report, the image source is set to External and the value for the image is the URL to the image. For a report published to a report server configured for native mode, use a full or relative path. You could store the images on the file system and use the database to keep a file-pointer, which is simply the path to the location of the image on your system. This is applicable if images will be kept in a permanent location and will be shared or accessed by other reports. Use a query to fetch the location, and use that as you would for any image. You also need to set the external image property too in the code behind of your application. See the code below.
reportViewer1.LocalReport.EnableExternalImages = true;
If you need to make configurable external image in SSRS 2008 use the global field ReportServerUrl to get the URL of the report server on which the report is being run dynamically (TargetServerURL). Let's say we have the image Logo.jpg in the Images folder on the Report Server, we can set the external image value in the report to the expression as shown in the code below.
=Globals!ReportServerUrl & "?/Image/Logo.jpg"
After deploying the report to the Report Server, the expression will be evaluated for the image path on the Report Server.
There will be a need to do additional tweaks to migrate a server report to a local report. If the server report uses an external image located in the same folder of the report catalog, you may need to re-adjust the image path. The Report Viewer won't attempt to load the image from the current application directory by default. As a workaround, you should use the file:// protocol to load external images. See example below.
file:///D:/MSSQLTIPWriting/2012_01/SampleReport/sherlee.jpg
You can add images that are stored in a database to your report. Such an image is known as a data-bound image. You use the same Image report item as the one used for static images, but with a set of properties that indicate that the image is stored in a database. Data-bound images can also be displayed from binary data stored in a database. Storing images in the database, normally called BLOBs (binary large object) is a usual process when you work with data.
There are a few different ways how to store the images for your reports, but choosing the right option always depends on the resources your client can afford and their business needs. Using the appropriate image source still depends where the images are stored. Now we are aware that each option has advantages and disadvantages, it is just a matter choosing the best option and maximizing the resources available. Otherwise you can suggest the latest technology that offers the best solution to meet the business needs.
| Share: | Share | Tweet |
|
![]() |
![]() |
Free SQL Server Learning |
| Tuesday, February 21, 2012 - 6:12:15 AM - Eduard | Read The Tip |
|
This is great! Thanks! |
|
| Wednesday, February 22, 2012 - 3:41:17 AM - abc | Read The Tip |
| How about advantages and disadvantages of each when exporting the report and the implications around cell merge (when images are used in header) - to be honest, the above I would be willing to trade off a number of the above disadvatages if cell merge was actually realistically/reliably resolved | |
| Wednesday, February 22, 2012 - 6:41:41 AM - Mike Gilbert | Read The Tip |
|
The file:// URL in your example is incorrect - see for example Wikipedia (http://en.wikipedia.org/wiki/File_URI_scheme) for the correct syntax. In your example, the correct URL would be: file:///D:/MSSQLTIPWriting/2012_01/SampleReport/sherlee.jpg Thanks for the informative article!
|
|
| Wednesday, February 22, 2012 - 10:19:38 AM - Sherlee | Read The Tip |
|
To abc, Advantages and disavantages of each when exporting the report is not the scope of my topic in this tip. However, I will try to explore regarding exporting the report and I will write another article for that. If you need to used images in your report header you can create a subreport that contain only the image you need for your report header for example a company logo. You can also reuse that sub report in any report where you need to include the company logo as one of the item in your report header. |
|
| Wednesday, February 22, 2012 - 10:38:40 AM - Sherlee | Read The Tip |
|
To Mike Gilbert, The file:// URL is not incorrect. Your given URL link answers and explain everything. But for the sake of other readers I will include a part of it here. A file URL takes the form of "file://host/path".
where host is the fully qualified domain name of the system on which the path is accessible, and path is a hierarchical directory path of the form directory/directory/.../name. If host is omitted, it is taken to be "localhost", the machine from which the URL is being interpreted. Note that when omitting host you do not omit the slash ("file:///foo.txt" is okay, while "file://foo.txt" is not, although some interpreters manage to handle the latter).
On my report this one works for me.
file://D:\MSSQLTIPWriting\2012_01\SampleReport\sherlee.jpg
Meaning of slash character
The slash character (/), depending on its position, is used in different meanings in a file URL.
The // after the file: is part of the general syntax of URLs. (The double slash // should always appear in a file URL according to the specification, but in practice many Web browsers allow you to omit it, in some cases at least.)
The single slash between host and path is part of the syntax of file URLs.
And the slashes in path separate directory names in a hierarchical system of directories and subdirectories. In this usage, the slash is a general, system-independent way of separating the parts, and in a particular host system it might be used as such in a pathname (as in Unix systems).
This is one is also correct because this is the correct URI as understood by the Windows Shell API. file:///D:/MSSQLTIPWriting/2012_01/SampleReport/sherlee.jpg To all the readers thank you very much for appreciating this article.
|
|
| Wednesday, February 22, 2012 - 10:54:08 AM - Sherlee | Read The Tip |
|
To Mike Gilbert, Here's Additional info for you. This is from http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx. Check this out when you have time. And also take note that I used file://D:\MSSQLTIPWriting\2012_01\SampleReport\sherlee.jpg to my report to indicate or assign the file location of my external image. I did not execute it in my IE or Firefox browser.
For the sake of other readers I include some part below regarding the proper syntax. If you will use URL use file:\\ If you will use URI use file:\\\
Proper SyntaxFor the UNC Windows file path The corresponding valid file URI in Windows is the following: For the local Windows file path The corresponding valid file URI in Windows is: |
|
| Wednesday, February 22, 2012 - 5:48:34 PM - Adjunctor | Read The Tip |
When to use Database as Images Source
Really?
I suppose it sounds ridiculously obvious but maybe it will help beginners. |
|
| Wednesday, February 22, 2012 - 11:28:12 PM - Sherlee | Read The Tip |
|
To Adjunctor, Yeah I include it just to be specific though its pretty obvious. Just in-case there are readers who has no any background about this topic or just beginning to learn new technical skills.
Thanks for reading my article.
|
|
| Thursday, February 23, 2012 - 2:21:32 PM - Marco Polo | Read The Tip |
|
Sherlee, Your sugestion about put the image in a sub-report and use it as a report header has a problem. The reporting services does not allow put a sub report inside a page header area. This is a greate article.
|
|
| Monday, February 27, 2012 - 2:46:26 PM - Lori | Read The Tip |
|
Thank you. Very good article! |
|
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |