Groups | Blog | Home
all groups > sql server reporting services > october 2004 >

sql server reporting services : Using Custom Assembly to Render Images


tommytan25 NO[at]SPAM yahoo.com
10/23/2004 1:05:25 AM
Hi,

After reading an article on
htttp://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.sqlserver.reportingsvcs&mid=2b9ec7af-94ba-471f-afa6-4e6e852af505&sloc=en-us,
I created a simple custome assembly with codes like below to test it
out:
===========================================================================
using System;
using System.IO;

namespace RSCustomAssembly
{
/// <summary>
/// Summary description for RSCustomAssembly.
/// </summary>
public class Charts
{
public Charts()
{
//
// TODO: Add constructor logic here
//
}

public static string HelloWorld()
{
return "Hello World!";
}

public static byte[] TestPicture()
{
FileStream oFileStream = new
FileStream(@"D:\logo.gif",FileMode.Open, FileAccess.Read);
byte[] result = new byte[oFileStream.Length];
oFileStream.Position = 0;
oFileStream.Write (result, 0, (int)oFileStream.Length);
return result;
}
}
}

===========================================================================

Then, I created an image named "image1" in my report template with to
follow properties:

Image Type = Database
Image MIME Type = image/gif
Value = RSCustomAssembly.Charts.TestPicture()

When preview the report, the image was not loaded. Checking the output
pane of VS.NET it has 2 warning message saying:
The value expression for the image ‘image1' contains an error: Stream
does not support writing.
The value expression for the image ‘image1' did not evaluate to an
image.

can any expert help me and see what is wrong? Instead of rendering the
image, using HelloWorld method did return the exact text in a textbox
and I'm just wonder why the image function just don't work.

I need this to run so to change my report to improve the performance
of the RS. Please help, thanks!

Scott Allen
10/23/2004 1:34:19 PM
Hi CCC:

You want to read bytes from the file into the buffer using
oFileStream.Read. The write method is trying to move bytes from the
buffer into a file opened in read only mode - that's the source of
your error.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

[quoted text, click to view]
Scott Allen
10/23/2004 1:46:50 PM
P.S.

Make sure to close the FileStream asap. The following is an effecient
and safe practice to do this:

using(FileStream oFileStream = new FileStream("<gifname>", ...))
{
...
}

At the end of the using code block the Dispose method will be invoked
and clean up file handle you have open.

--
Scott
http://www.OdeToCode.com/blogs/scott/

[quoted text, click to view]
AddThis Social Bookmark Button