Word document saved to SQL Server as Image - retrieves incorrectly

K

K B

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:
 
W

Winista

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.
 
Top