How to create a dynamic company logo for reports

Have you ever needed to dynamically change the company logo displayed on a report? This technique will work for Visual Studio 2005 and 2008.  You’ll need to create a table in SQL Server to store the company name and logo, basic table would look like this:

CREATE TABLE [ReportCompanyLogo](
    [CompanyName] [varchar](100) NOT NULL,
    [Logo] [varbinary](max) NOT NULL

To add a company logo to this table, use syntax like:

INSERT into [ReportCompanyLogo] (CompanyName, Logo)
Select 'Acme Company' As CompanyName,
    * FROM OPENROWSET(BULK 'C:\ACME_LOGO.jpg', SINGLE_BLOB) AS Logo

Using Visual Studio BIDS we define a Report dataset, note the creation of a calculated field;

Field Name: ImageBase64

Type: Calculated Field

Value (include ‘=’)

=Convert.ToBase64String(Fields!Logo.Value)

Note: a stored procedure was created to retrieve the logo based on the company name passed.

clip_image002

Define a report parameter named Image, specify the new dataset in the From Query section:

clip_image004

For the report logo, specify:

Value = Convert.FromBase64String(Parameters!Image.Value)

image

Once invoked, you’ll retrieve the company logo:

image

Published Wednesday, February 10, 2010 6:00 PM by sthompson
Filed under: , ,

Comments

No Comments
Powered by Community Server (Commercial Edition), by Telligent Systems