Frans, Chad,

Thanks for the reply, but I am not sure if I understand your answers.

Chad wrote:

> Use the img tag:  <img src="getimagepage.aspx?imageid=1234">

> Then in your getimagepage.aspx get the image bytes and perform a
> Response.BinaryWrite() and set the ContentType to whatever is
> appropriate for the image being pulled from the db.

Frans wrote:

> Create a separate .aspx page, which doesn't have any HTML. In the code
> behind you load the image into a memory stream and you stream that data
> towards the browser by writing it into the response, setting the
> appropriate headers. (so clear the headers first):

> Response.ClearHeaders();
> Response.AddHeader("Content-Type", "application/unknown");
> Response.AddHeader("Content-Disposition");
> Response.AddHeader("Content-Transfer-Encoding", "Binary");
> Response.BinaryWrite(fileContents);

> You then do in your normal webpage:
   <!-- some html -->

   <IMG SRC="myImageLoader.aspx?ImageID=343232">

> and you then pass the image id to load to the page, I now used a
> hardcoded number.


Here is the code that I use to read the image from the database, and send
it to the disk:

        Dim fs As FileStream                 ' Writes the BLOB to a file
(*.bmp).
        Dim bw As BinaryWriter               ' Streams the binary data to
the FileStream object.

        Dim bufferSize As Integer = 100      ' The size of the BLOB buffer.
        Dim outbyte(bufferSize - 1) As Byte  ' The BLOB byte() buffer to
be filled by GetBytes.
        Dim retval As Long                   ' The bytes returned from
GetBytes.
        Dim startIndex As Long = 0           ' The starting position in
the BLOB output.

        conClsf = New SqlConnection('connection stuff)
        conClsf.Open()

        strSQL = "select   ImageFileName as ImageFileName, " & _
                  "         SketchImage as SketchImage " & _
                  "from     tblSketchImages "

        cmdSketch = New SqlCommand(strSQL, conClsf)

        rdrSketch = cmdSketch.ExecuteReader
(CommandBehavior.SequentialAccess)

        Do While rdrSketch.Read()
            strFileName = rdrSketch.Item("ImageFileName")

            ' Create a file to hold the output.
            fs = New FileStream(strFileName, FileMode.OpenOrCreate,
FileAccess.Write)
            bw = New BinaryWriter(fs)

            ' Reset the starting byte for a new BLOB.
            startIndex = 0

            ' Read bytes into outbyte() and retain the number of bytes
returned.
            retval = rdrSketch.GetBytes(1, startIndex, outbyte, 0,
bufferSize)

            ' Continue reading and writing while there are bytes beyond
the size of the buffer.
            Do While retval = bufferSize
                bw.Write(outbyte)
                bw.Flush()

                ' Reposition the start index to the end of the last buffer
and fill the buffer.
                startIndex += bufferSize
                retval = rdrSketch.GetBytes(1, startIndex, outbyte, 0,
bufferSize)
            Loop

            ' Write the remaining buffer.
            bw.Write(outbyte, 0, retval - 1)
            bw.Flush()

            ' Close the output file.
            bw.Close()
            fs.Close()
        Loop


This snippet came directly from the MSDN stuff.

How can I use this to "write" the image to an ASPX page?  If it helps, the
images are GIF files.

Sorry, but I am new to VB.NET and ASP/ASPX.  Please bear with me.

Thanks,
  Bryan

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with CSharp
August 30 - September 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to