By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,288 Members | 3,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,288 IT Pros & Developers. It's quick & easy.

How to display image blob from database?

P: n/a
How can I display photo images stored in a SQL Server 2000 databases in a
DataList or DataGrid without having to write the images to files first?

Olav
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You should be able to stream them by setting the right mime type in your
output.

"Olav Tollefsen" <x@y.com> wrote in message
news:Oj**************@TK2MSFTNGP10.phx.gbl...
How can I display photo images stored in a SQL Server 2000 databases in a
DataList or DataGrid without having to write the images to files first?

Olav

Nov 18 '05 #2

P: n/a
Olav

You need a url that returns the image you want, which you bind to each listitem in your datagrid/datalist, e.g. <img src='<%# "GetImage.aspx?src=" + ID %>'

In this example, GetImage.aspx uses the ID you pass and does the i/o to get a byte array from the blob, then returns it in the output stream as a picture, e.g
response.ContentType = "image/jpeg"
response.BinaryWrite(MyByteArray

The other nice thing about using GetImage is that you can very simply modify the image before you return it to the stream, such as add a description or copyright notice onto the picture, return a thumbnail, etc. In that case, you'd create your bitmap from the blob, modify it however, then do bitmap.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg) to output it to the stream

For a great discussion of this and a lot more, check out Esposito's Programming Microsoft ASP.NET from MS Press (pp. 1036-1044)

hth

Bil

----- Olav Tollefsen wrote: ----

How can I display photo images stored in a SQL Server 2000 databases in
DataList or DataGrid without having to write the images to files first

Ola

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.