473,804 Members | 3,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Word document saved to SQL Server as Image - retrieves incorrectly

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

Dim iImageSize As Integer = FileUpload.Post edFile.ContentL ength
Dim picbyte() As Byte = New Byte(iImageSize ) {}
FileUpload.Post edFile.InputStr eam.Read(picbyt e, 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(Sess ion("ImageConte nt"), Byte())
Dim ms1 As New System.IO.Memor yStream(arrImag e)
Response.Binary Write(arrImage)
Response.Conten tType = Session("Conten tType")
Response.Output Stream.Write(CT ype(Session("Im ageContent"), Byte()), 0,
CInt(Session("I mageSize")))
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ММšgUg UgU‡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 ***
Jun 5 '06 #1
1 3187
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" <ka**********@c omcast.net> wrote in message
news:ej******** *****@TK2MSFTNG P02.phx.gbl...
I'm using the following in .NET to save a Word document to a SQL image
column:

Dim iImageSize As Integer = FileUpload.Post edFile.ContentL ength
Dim picbyte() As Byte = New Byte(iImageSize ) {}
FileUpload.Post edFile.InputStr eam.Read(picbyt e, 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(Sess ion("ImageConte nt"), Byte())
Dim ms1 As New System.IO.Memor yStream(arrImag e)
Response.Binary Write(arrImage)
Response.Conten tType = Session("Conten tType")
Response.Output Stream.Write(CT ype(Session("Im ageContent"), Byte()), 0,
CInt(Session("I mageSize")))
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оNR0OLO sfsfsfsfsfsfs$ johвzLЇs^?R zNzN@?R?RЇs^
^ЖKтKММsgUg UgU?Rd^ЖK^тK sgU?RsgUgU2 Ј^^йЖK,LK
АіYЋvЦ"IыRpНZ b-.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 ***

Jun 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
13293
by: Joan | last post by:
I am creating a word document from an asp page. I have no problems actaully creating the document and creating some tables that have data in them. I am using Response.ContentType = "application/vnd.ms-word" to create the actual document. My problem is that I want to place a picture (which resides on the server) into the word document as well. However all I seem to get is the place for the image but a picture of an "x" meaning that the...
0
1013
by: kstriyhon | last post by:
i need to build a word document from a sql 2000 database and i need this word document to be saved in the client machine not in the server. is this possible?? how can i do this? i mean i need to build the word document when the user click a link in a web page using some idТДs the user send the server when he does that. once the word document is builded i need this document to be saved in the client machine.
3
4662
by: tigrrgrr42 | last post by:
I am working(vb.net03and05) with word documents stored in a sql db and I am currently bringing them from a byte array into a temp file to pop into word and make word do its thing as a com object. Is it possible to go straight from a byte array to document in word instead of a temp file? Also is there a way to change the save behaviour to notify my app to pickup a binary copy of the file or stream to save back to the sql db. Thanks in...
7
6253
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the user and populated (with info from an Access database) at run-time, then saved as Word documents. The program I have coded works fine -- it does what I need it to do. But it has two problems: (1) it runs very slowly, and (2) it does not seem to...
1
1654
by: musicloverlch | last post by:
I have a problem. I have an Access 2003 report that contains a number of Word and Excel objects with fancy formatting and spreadsheets, etc. I have about 20 records that I am having the database cycle through and create one report per record (I need 20 individual PDFs for e-mailing). When I use the 'DoCmd.OpenReport "rptAnnualPkg", acViewNormal', Access prints it before all the Word and Excel objects load and I have reports with huge...
2
3178
by: gerard.buskermolen | last post by:
Hello world, I have an ASP.NET application that returns HTML to the browser that should be read by MS Word. To do this I set Response.ContentType = ContentType.Word and render the HTML. The browser (IE6.0) shows a dialog box which enables the user to Open the HTML in Word or save it to disk. So far so good.
0
1228
by: gerard.buskermolen | last post by:
Hello world, I have an ASP.NET application that returns HTML to the browser that should be read by MS Word. To do this I set Response.ContentType = ContentType.Word Response.AddHeader("Content-Disposition", "Report.doc") and render the HTML.
4
5520
by: jefftim | last post by:
Hi All I've saved a word document in sql server database.I'm able to retrieve it from the database and open it in a word application. My problem is as i have to use this in an intranet application, the word is not opening in a client machine but it is opening on the machine the application has been hosted. I'm extracting the word file from database and storing it on the hard disk and in the next instance passing the file location to...
2
5002
by: s.danyal.k | last post by:
Hi All, I have created an application in C# that converts HTML file to MS word documents. The HTML file may also have images , for e.g "<img src='http://www.google.com.pk/images/hp0.gif'></img>". The HTML file saved into .doc file. Now the problem is that whenever the .doc file is opened it goes to the link mentioned in the <imgtag. This means that only the link is saved in the .doc file and not the ACTUAL image. Now I want the actual...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10310
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprщ who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.