Word document saved to SQL Server as Image - retrieves incorrectly

Discussion in 'ASP .Net' started by K B, Jun 5, 2006.

  1. K B

    K B Guest

    I'm using the following in .NET to save a Word document to a SQL image
    column:

    Dim iImageSize As Integer = FileUpload.PostedFile.ContentLength
    Dim picbyte() As Byte = New Byte(iImageSize) {}
    FileUpload.PostedFile.InputStream.Read(picbyte, 0, iImageSize)

    Seems to work fine, but when I retrieve the image and use the following
    to load it, I get a lot of characters, etc. What am I doing wrong
    please?

    Response.Clear
    Dim arrImage() As Byte = DirectCast(Session("ImageContent"), Byte())
    Dim ms1 As New System.IO.MemoryStream(arrImage)
    Response.BinaryWrite(arrImage)
    Response.ContentType = Session("ContentType")
    Response.OutputStream.Write(CType(Session("ImageContent"), Byte()), 0,
    CInt(Session("ImageSize")))
    Response.End()

    I get the content but with a lot of extra stuff in it:

    ÐÏࡱá>þÿ
    áãþÿÿÿßàÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    ÿÿÿÿÿÿÿÿì¥Á` ø¿æ"bjbjËsËs
    Ó§©©Êÿÿÿÿÿÿ¤ˆˆˆˆˆˆˆœ„I„I„I8¼Id
    J,œ›hXKXK^¶K¶KâKÞNR0OLOšƒšƒšƒšƒšƒšƒš$jœhÒžL§šˆ‡RžNžN@‡R‡R§šˆ
    ˆ¶KâK¼¼šgUgUgU‡Rdˆ¶KˆâKšgU‡RšgUgU2¨ˆˆÙ¶K,LK
    °öŸ«vÆ„IëRp½Žb-•TÒš0›º [S¨ \Ù
    ˆñ<\O„àO^gU>PLŠPý\O\O\O§š§šUd\O\O\O›‡R‡R‡R‡Rœœœd8„œœœ8œœ
    œˆˆˆˆˆˆÿÿÿÿ To:





    *** Sent via Developersdex http://www.developersdex.com ***
    K B, Jun 5, 2006
    #1
    1. Advertising

  2. K B

    Winista Guest

    All MS Office applications use OLE Document format to store the data and a
    lot of time you will find buffer bytes used as paddind to fillers to fill
    512byte blocks. MS Office applications know how to read them back. Do a
    simple test, read the data back into a word file and if it opens and
    contents are intact.


    "K B" <> wrote in message
    news:...
    > I'm using the following in .NET to save a Word document to a SQL image
    > column:
    >
    > Dim iImageSize As Integer = FileUpload.PostedFile.ContentLength
    > Dim picbyte() As Byte = New Byte(iImageSize) {}
    > FileUpload.PostedFile.InputStream.Read(picbyte, 0, iImageSize)
    >
    > Seems to work fine, but when I retrieve the image and use the following
    > to load it, I get a lot of characters, etc. What am I doing wrong
    > please?
    >
    > Response.Clear
    > Dim arrImage() As Byte = DirectCast(Session("ImageContent"), Byte())
    > Dim ms1 As New System.IO.MemoryStream(arrImage)
    > Response.BinaryWrite(arrImage)
    > Response.ContentType = Session("ContentType")
    > Response.OutputStream.Write(CType(Session("ImageContent"), Byte()), 0,
    > CInt(Session("ImageSize")))
    > Response.End()
    >
    > I get the content but with a lot of extra stuff in it:
    >
    > ÐÏࡱá>þÿ
    > áãþÿÿÿßàÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    > ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    > ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    > ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    > ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    > ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
    > ÿÿÿÿÿÿÿÿì¥Á` ø¿æ"bjbjËsËs
    > Ó§©©Êÿÿÿÿÿÿ¤^^^^^^^o"I"I"I8¼Id
    > J,o>hXKXK^¶K¶KâKÞNR0OLOsfsfsfsfsfsfs$johÒzL§s^?RzNzN@?R?R§s^
    > ^¶KâK¼¼sgUgUgU?Rd^¶K^âKsgU?RsgUgU2¨^^Ù¶K,LK
    > °öY«vÆ"IëRp½Zb-.TÒs0>º [S¨ \Ù
    > ^ñ<\O"àO^gU>PLSPý\O\O\O§s§sUd\O\O\O>?R?R?R?Roood8"ooo8oo
    > o^^^^^^ÿÿÿÿ To:
    >
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    Winista, Jun 5, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    6,130
  2. Replies:
    0
    Views:
    388
  3. Replies:
    2
    Views:
    641
  4. S.Sigal
    Replies:
    0
    Views:
    129
    S.Sigal
    Aug 14, 2004
  5. ~~~ .NET Ed ~~~

    An ImageButton that retrieves its image from a Resource

    ~~~ .NET Ed ~~~, Apr 2, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    402
    Robert Rae
    Jun 22, 2005
Loading...

Share This Page