2015-06-18

SSRS Replace Embedded Image Dynamically Part 1 - Prepare the Project

Back to few months ago, one of our clients had a re-brand campaign. As a result, all of its related reports needs to be modified, because of the logo change.

As you know, in the native reporting service, there are three ways to hold an image on the report:
  • Embedded Image saved in the report
  • Database Stored Image saved in the database
  • External Image can be in a network shared folder or a web site hosted image

In my case, if the logo was created by using the 2nd way or the 3rd way, it is simple to change: just replace the referenced target. But there were some reports are using embedded image. It means we have to open the report in edit mode, and verify the image storage type, and then change it if applicable. Time consuming, isn't it?


If you google the question, an old post (here) gives a way to extract embedded images from the RS report. However I could not find the source code though author mentioned "you can download the source code using the link at the top" :(

But at least it gives me some thoughts. So I am going to show you how to dynamically replace the embedded images of the RS report through C# code.

Firstly, let's create the project and add references we need.



Now to simplify our job, we need to grab the report definition from Microsoft. You can find the definition here. Open this xsd in the web broswer and save this into the project folder.


Time to generate class definition from our downloaded XSD. Open Visual Studio command prompt window, navigate to the project folder, and type

xsd /c /n:SampleRDLSchema ReportDefinition.xsd

The cs file should be generated within the project folder.


Now we add this newly created class file into our project, in my project, it is ReportDefinition.cs


Next step is to add web service reference to our reporting service. In the project, right click Service References folder and select "add service references"


On the pop up window, click "Advanced..." button located at the bottom right corner.


now we get the 2nd pop up window, at the bottom of this window, click button "Add Web References"


Finally we reach the window we want. in this window, input our reporting service address, it should be http://<server>/reportserver/reportservice2010.asmx. As you can see in above window I named it as RS2010.

After click "Add Reference" button, your project should look like below


Before we do some coding jobs, a finaly step is to add using clauses we need:

using System.IO;
using SSRS_ReplaceImages.RS2010;
using System.Xml.Serialization;
using System.Drawing.Imaging;


After you add these using clauses, we are ready to replace the image in the report, which will be covered in my next post. :P






No comments :

Post a Comment