Geeks With Blogs
The Quandary Phase This code was generated by a tool.

Ran into a slightly problematic issue today: I was working on an SSRS report project which had been pulled down from source control. The project contains several reports, each of which contains a number of embedded images. I was tasked with developing a number of new reports, each of which had to follow the same styling.

All well and good so far, but I quickly realised that the source image files had not also been committed to version control; the images existed only within the XML of the report RDL files.

The SSRS designer doesn’t provide any method by which to copy embedded images from one report to another, so my problem was twofold: firstly, I needed to find a method to copy an embedded image between reports, and secondly, I needed to find a method to extract the embedded image from the RDL file so the image file itself could be committed to source control to make life easier for future developers working on the project.

The first problem has several simple solutions. The easiest of all is to just copy-and-paste an existing RDL file into the project directory, rename the copied file and then delete all of its content via the Business Intelligence Studio designer. This will result in a new, empty report, which can be used as a template- and it will still contain all the embedded images/custom code etc as the original.

Unfortunately (for me) I had already started development on one of the reports when I realised this was a problem, and I wanted to keep my existing report file, so I needed a way to import the embedded image into my existing report.

It turns out that this is also easy enough. In order to do this you can open the RDL file which contains the embedded images in notepad, navigate down the XML until you find the EmbeddedImages node, then copy this node and all of its children into the new report- to the same location, below the root Report node.

The embedded images node looks something like this:

   1: <EmbeddedImages>
   2:   <EmbeddedImage Name="aircargo_jpg">
   3:     <MIMEType>image/jpeg</MIMEType>
   4:     <ImageData>/9j/4AAQSkZJRgABAQEAYABg...</ImageData>
   5:   </EmbeddedImage>
   6: </EmbeddedImages>

The second problem was a bit trickier. Once again, SSRS doesn’t provide an out-of-the-box solution to enable you to save an existing embedded image to disk- once it has been embedded, there’s no straightforward way to get it back out again (this is true of both BIDS 2005 and BIDS 2008- hopefully Microsoft will add this functionality for the next SQL Server and BIDS release).

All the image data is in the XML; as you can see in the markup above, there is a parent EmbeddedImages node which contains a collection of EmbeddedImage nodes. Each embedded image has a Name attribute, a child node which describes the image MIME type, and another child node which contains the image binary contents encoded as a base64 string.

Ultimately, I came up with a little windows app to extract the images to file for me. The code loads a given RDL file into a new XmlDocument instance, locates the EmbeddedImages parent node, then iterates over each of the embedded image child nodes, writing the content to disk.

Although there have been many changes to the RDL XML structure between SSRS 2005 and SSRS 2008, the embedded images XML is the same in both, so this solution will work with either version.

Hopefully this utility will be of use to somebody- you can download the source code using the link at the top.

Posted on Wednesday, July 22, 2009 11:25 AM | Back to top


Comments on this post: Extracting Embedded Images From SSRS Reports

# re: Extracting Embedded Images From SSRS Reports
Requesting Gravatar...
RE:SSRS Image Extractor...very nice Adam!
Left by Thomas Williams on Jul 22, 2009 8:08 PM

# re: Extracting Embedded Images From SSRS Reports
Requesting Gravatar...
the link on live.com doesn't work if you have webwasher running (as our company does). The file contents and file type don't match, so it kills the download. Is there another way to get this?
Left by Chris Marcum on Jan 18, 2010 7:20 AM

# re: Extracting Embedded Images From SSRS Reports
Requesting Gravatar...
Great article, hey I stumbled on to this post while searching the web for random downloads. Thanks for sharing I’ll email my friends about this too.
Left by bailey button triplet 1873 grey on Nov 17, 2010 6:18 PM

# re: Extracting Embedded Images From SSRS Reports
Requesting Gravatar...
Your blog article is very intersting and fantastic,at the same time the blog theme is unique and perfect,great job.To your success.One of the more impressive blogs Ive seen. Thanks so much for keeping the internet classy for a change.I ran across search engines and find this blog that fulfill my needs. There is a thing I do not agree but It doesn't matter since I think it does not hurt the whole content.The file contents and file type don't match, so it kills the download. Is there another way to get this?
Indonesian Furniture | Indonesian Teak Furniture.
Left by John Agung Vanderbilt on Dec 07, 2010 5:05 AM

# re: Extracting Embedded Images From SSRS Reports
Requesting Gravatar...
Can you repost the file? it doesn't appear to exist any longer
Left by Lee on Jan 26, 2011 3:59 AM

# re: Extracting Embedded Images From SSRS Reports
Requesting Gravatar...

Hey,
It is a pretty good post. This post contains useful information which helps us a lot. I have never seen such a great post. your wonderful post can inspire a lot and helps us. I visit your website often and share with my friends.

Left by X Ray Technician Training on Mar 04, 2011 8:11 PM

Comments have been closed on this topic.
Copyright © Adam Pooler | Powered by: GeeksWithBlogs.net