Binding a SQL Image Column to an Image Control - Can I Avoid Saving The ByteStream/FileStream To Dis

B

Ben Willett

I have a C#/ASP.NET/ADO.NET/SQL Server app that stores and retrieves images.

The problem is the ASP Image control binds to a file. When retrieving an image from SQL, I would really like to avoid saving the ByteStream/FileStream to disk, just to then read it back into the Image control.
Is there a way to avoid this?

// This is my current implentation. It works, but requires lots of disk i/o.
// Write the ByteArray to a FileStream and then the FileStream to disk.
iLen = mySqlDataReader.GetBytes(0, 0, myByteArray, 0, lBufSize);
FileStream myFS = new FileStream(@"c:\image.jpg", FileMode.Create, FileAccess.Write);
myFS.Write(myByteArray, 0, iLen);
ASPImage1.ImageUrl = @"c:\image.jpg";

Thanks in advance,
Ben
 
?

=?iso-8859-1?Q?Fredrik_Norm=E9n_NSQUARED2?=

You can create an ASP.Net page that reads the image from
the data base (I shouldn't store an image into the
database becuase it affects the performance) and put the
image stream to the HttpResponse.OutputStream.

Set the Response.ContentType to an image type.

Then you can set the ImageUrl of the Image control to the
site that renders the image, something like:

ASPImage1.ImageUrl = @"myImageReander.aspx?id=" +
myImageId;

/Fredrik Normén NSQUARED2
http://www.nsquared2.net

-----Original Message-----
I have a C#/ASP.NET/ADO.NET/SQL Server app that stores and retrieves images.

The problem is the ASP Image control binds to a file.
When retrieving an image from SQL, I would really like to
avoid saving the ByteStream/FileStream to disk, just to
then read it back into the Image control.
Is there a way to avoid this?

// This is my current implentation. It works, but requires lots of disk i/o.
// Write the ByteArray to a FileStream and then the FileStream to disk.
iLen = mySqlDataReader.GetBytes(0, 0, myByteArray, 0, lBufSize);
FileStream myFS = new FileStream(@"c:\image.jpg",
FileMode.Create, FileAccess.Write);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top