Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display a word document from sql server

Status
Not open for further replies.

jordan11

Technical User
May 24, 2003
150
GB
I am trying to display a word documnet from my sql server database using

<%
set rs=server.createobject("ADODB.recordset")
txtSQL= "SELECT filedata FROM clientcv WHERE clientID = '" & REQUEST("clientid") & "'"
Set rs=conn.Execute(txtSQL)



'Response.Expires = 0
'Response.Buffer = TRUE
'Response.Clear



Response.ContentType = "application/msword"


Response.BinaryWrite RS("filedata")


RS.Close
Set RS = Nothing
%>


but the results I get is


ÐÏࡱá





Thanks in advance
 
Thanks for the reply

Not sure how to use that
 
and as far using HTMLEncode() function we use it something like this...

Response.Write Server.HTMLEncode(RS("filedata"))

-DNG
 
Thanks DNG

The I have below will display an image but will not display a word docoment do you have any ideas on what the problem is.

<%
Response.CacheControl="no-cache"
Response.AddHeader "pragma", "no-cache"
Response.Expires = -10
Response.Buffer = True
Response.Clear



ID = Request.QueryString("ID")
BlockSize = 4096
Response.ContentType = "application/msword"
set rs=server.createobject("ADODB.recordset")
txtSQL= "SELECT * FROM Physiciancv where physicianID ='11'"
Set rs=conn.Execute(txtSQL)
RS.MoveFirst
Set Field = RS("filedata")
FileLength = Field.ActualSize
NumBlocks = FileLength \ BlockSize
LeftOver = FileLength Mod BlockSize
Response.BinaryWrite Field.GetChunk(LeftOver)
For intLoop = 1 To NumBlocks
Response.BinaryWrite Field.GetChunk(BlockSize)
Next
RS.Close
Set RS = Nothing
%>

 
If you write it to a file instead of to the response object, do you get a valid .doc file?
 
when I submit it goes to a word document the gives me the option to convert file when I whatever I select I still get
ÐÏࡱá
 
If you can't use that database field to write a valid .doc file onto your hard disk then perhaps the field doesn't contain a valid doc file.
 
Not sure what you mean as the document that was inserted is a valid word doc so would it not just retrieve the same doc out of the database.
 
Not sure on this one but aren't office docs encoded in some way that requires decoding?

I.E. Create a Word doc and save it, then open it with notepad and you'll see the same results as you're getting.

To display directly on the page as you're attempting wouldn't you need to use the MS Word object libraries to open the file and take the text from there?

Rhys
"There are some oddities in the perspective with which we see the world. The fact that we live at the bottom of a deep gravity well, on the surface of a gas-covered planet going around a nuclear fireball 90 million miles away and think this to be normal is obviously some indication of how skewed our perspective tends to be"
DOUGLAS AD
 
Rhys666, I don't think jordan11 wants the text... they want to send the file itself... like what happens if you drag/drop a word file into Internet Exploder.
 
Which would mean streaming the file into the Response, but what appears to be happening is the content of the Reposnse object is not being interpreted properly at the client, or the writing of the file to the Response stream is incorrect.

1) Is MS Word installed on your machine that you're viewing the page from?
If it isn't, thats likely to be your problem as your machine can't read an MS Word .doc file. If it is, are you certain Response.BinaryWrite is the appropriate method for a Word doc?

Rhys
"There are some oddities in the perspective with which we see the world. The fact that we live at the bottom of a deep gravity well, on the surface of a gas-covered planet going around a nuclear fireball 90 million miles away and think this to be normal is obviously some indication of how skewed our perspective tends to be"
DOUGLAS AD
 
Response.BinaryWrite is the proper command to use in this case...but i am not sure why its not being displayed correctly..

may be you are correct in saying that MS word is not installed on the client machine...but if that is the case..the code should prompt for saving or opening the file using some program instead of displaying weird characters

-DNG
 
change your sql statement to specific the exact field instead of putting a *

txtSQL= "SELECT * FROM Physiciancv where physicianID ='11'"

instead try something like

txtSQL= "SELECT blah FROM Physiciancv where physicianID ='11'"

-DNG
 
and make sure that BLOBs are the last things in your SELECT statement

also shouldnt that be physicianID=11 instead of physicianID='11'

-DNG
 
I will give all your suggestions a try

Thanks
 
DotNetGnat said:
Response.BinaryWrite is the proper command to use in this case...but i am not sure why its not being displayed correctly..
I wasn't sure as I've spent so much time with .Net recently my ASP 3.0 head has gone off the boil.


DotNetGnat said:
may be you are correct in saying that MS word is not installed on the client machine...but if that is the case..the code should prompt for saving or opening the file using some program instead of displaying weird characters
I agree, the characters displayed are like those you'd expect opening a .doc file in note pad which is why it sprang to mind - the file type associations on the client machine might be dodgy though, oh, and is the MSWord MIME type set up on the server?

Rhys
"There are some oddities in the perspective with which we see the world. The fact that we live at the bottom of a deep gravity well, on the surface of a gas-covered planet going around a nuclear fireball 90 million miles away and think this to be normal is obviously some indication of how skewed our perspective tends to be"
DOUGLAS AD
 
ms word is installed and I tried what you suggested but it still only works with images.


Thanks
 
I have the same exact problem.

I even tried directly streaming from a file. The source DOC is valid, the destination is twice(2) the size, and all junked up as described.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top