"I figured it out. Here is the code if you are interested. It is quite rough right now and without proper exception try-catch blocks, but it does work well. Also, the SQL statement is different because I am using this page to pull only the ThumbNail image from a table which stores Thumbnails along with High-Res images. Thanks for the great work on the .NET sites. They really save me a ton of time." Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here 'Extract the ID out of the URL Dim imgID As String imgID = Request.QueryString("id") 'Uses the System.Configuration Class to extract DSN string from the web.config Dim objConnection As SqlConnection objConnection = New SqlConnection(ConfigurationSettings.AppSettings("imgarchive")) Dim objCommand As SqlCommand = New SqlCommand() objCommand.Connection = objConnection objCommand.CommandText = "select DigitalFile, ContentType from tblDigitization " & _ "where (ThumbNail=1) and (ImageID=" & imgid & ")" objConnection.Open() Dim dr As SqlDataReader = objCommand.ExecuteReader() If dr.Read() Then Dim imgContentType As String = (dr.Item(("ContentType")).ToString()) Dim imgByte(dr.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte dr.GetBytes(0, 0, imgByte, 0, imgByte.Length) Dim imgStream As MemoryStream = New MemoryStream(imgByte) Dim img As Image = Image.FromStream(imgStream) Response.ContentType = imgContentType 'set the proper image format If (InStr(imgContentType, "jpeg")) Then img.Save(Response.OutputStream, ImageFormat.Jpeg) ElseIf (InStr(imgContentType, "gif")) Then img.Save(Response.OutputStream, ImageFormat.Gif) End If Response.Flush() Response.Close() imgStream.Close() End If objConnection.Close() End Sub |