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.