hi.
i've stuck up an example of how to return image/jpeg content from a database
(from an aspx page)
the example query simply selects an image, content-type, size, etc from a
table contaniing images.
If it was holding say word docs, the content type would be something like
"application/msword" - you need to check this (from memory) instead of
"image/jpeg"
and instead of calling the Image.Save() method, you'd simply write the
memory stream to the Response stream. (the reason there's an image object
there is because I've chopped out a section that does image manipulation
before writing to the response)
In a nutshell, select the blob, get memory stream, write the response
stream. make sure the Response.ContentType is right for the data your
returning.
HTH
Sam
private void Page_Load(object sender, System.EventArgs e)
{
string _iid = Request.QueryString["imgid"]+"";
int _imgid = int.Parse(_iid.Length==0?"0":_iid);
System.Drawing.Image _img;
if (_imgid !=0)
{
System.Data.SqlClient.SqlConnection Con = new
System.Data.SqlClient.SqlConnection();
Con.ConnectionString = DAL.Helper.DatabaseConnectString;
System.String SqlCmd = "SELECT * FROM schema.imagetable WHERE img_seq =
@imgid";
System.Data.SqlClient.SqlCommand SqlCmdObj = new
System.Data.SqlClient.SqlCommand(SqlCmd, Con);
SqlCmdObj.Parameters.Add("@imgid", System.Data.SqlDbType.Int).Value =
_imgid;
Con.Open();
System.Data.SqlClient.SqlDataReader SqlReader =
SqlCmdObj.ExecuteReader();
SqlReader.Read();
Response.ContentType = (string)SqlReader["img_contenttype"];
System.IO.MemoryStream mem = new
System.IO.MemoryStream((byte[])SqlReader["img_src"],0,(int)SqlReader["img_sizebytes"]);
_img = System.Drawing.Image.FromStream(mem);
_img.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
Con.Close();
}
Response.End();
}