Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2005, 05:43 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default Why user download word file is binary when open

Hi, all,
I create a word report in the server side, I try to force the client to save it. I test the program in my local server, when I open the download word file, it's binary file, why? I use the following codes:
'''''''''''''''''''''''''''''''''''''''''''''''''
   Response.Buffer = True
   strFileName = "reportWord.doc"
   response.addHeader "Content-"application/msword"
   Response.AddHeader "Content-disposition",
                       "attachment;filename=""" & strFileName & """"
   set fso = createobject("scripting.filesystemobject")
   set objTS = fso.OpenTextFile(docFileName,1)
   Response.BinaryWrite (objTS.ReadAll)
   Response.Flush
''''''''''''''''''''''''''''''''''
   I also use Response.Write (objTS.ReadAll), not right. I try to use Set Stream = Server.CreateObject("ADODB.Stream"), get eror.
What I want is when download dialog box appear, if use choose open, it display word format(binary is also OK), but when user open the saved file, it must be word format, include the page header/footer.

Can you help me for that, please.......

Andraw




 
Old January 15th, 2005, 02:34 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found that even I can use above(some type error caused by copy/paste, souce is right) to let user download word file, the header and footer are lost, did anybody has the same problem?

Andraw

 
Old January 15th, 2005, 02:53 AM
Authorized User
 
Join Date: Aug 2004
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Andraw

  While copying some unrecognized characters might have got included in your doc.
  Some months before i had the simillar problem.

  I had to replace all the unrecognized charecters with the curresponding html notations.

   Following were my code to solve this issue.


("str_doc" means the string which needs to be written as doc file.)
Code:
if instr(str_doc,chr(45)) > 0 then
    str_doc = replace(str_doc,chr(45),"–")
end if
if instr(str_doc,chr(189)) > 0 then
    str_doc = replace(str_doc,chr(189),"–")
end if
if instr(str_doc,chr(146)) > 0 then
    str_doc = replace(str_doc,chr(146),"’")
end if
if instr(str_doc,chr(145)) > 0 then
    str_doc = replace(str_doc,chr(145),"’")
end if
if instr(str_doc,chr(147)) > 0 then
    str_doc = replace(str_doc,chr(147),""")
end if
if instr(str_doc,chr(148)) > 0 then
    str_doc = replace(str_doc,chr(148),""")
end if
if instr(str_doc,chr(150)) > 0 then
    str_doc = replace(str_doc,chr(150),"–")
end if
if instr(str_doc,chr(151)) > 0 then
    str_doc = replace(str_doc,chr(151),"–")
end if
if instr(str_doc,"£") > 0 then
    str_doc = replace(str_doc,"£","£")
end if

Please let me know if this helps you.:)

 
Old January 15th, 2005, 10:21 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Shibu,
Thanks for response.
The word file is already created using CreateObject("Word.Application"), when do i have to replace the special character? your codes give me some instruction when I create the word file.

Andraw



 
Old January 17th, 2005, 12:24 AM
Authorized User
 
Join Date: Aug 2004
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Andraw

 You are right this replacements are are to be done while creatigng the word document.
 So, I believe you have a word file already created and saved on your server. Let me give you a suggession ( a wild guess).
   Instead of opening the doc and writing using binary write, why can't you directly link the original doc file.
  Fo eg.
  <a href ="xxx.doc" target="_blank">click here</a>


 Hope this is not foolishness.

 
Old January 17th, 2005, 12:41 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, Shibu,

the only reason is that I want the the download dialog box appear. and the display stream is read from the original file, if other user update the original file, it doesn't matter. otherwise, maybe there is a warning "other user is using the file, you cann't update it", my understanding is right?, I am in testing perion now, please give me more suggestion. thanks!

Andraw






Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't able to Open Word File in Client Machine senthilavs Classic ASP Basics 1 June 10th, 2006 01:02 PM
disable "open" in file download lian_a HTML Code Clinic 0 July 11th, 2005 03:36 AM
user ability to download a file elladi Classic ASP Basics 3 April 1st, 2005 07:40 AM
How to open a .DOC file with MS-Word ? sherbir Servlets 0 July 26th, 2004 02:39 AM
How to open Binary .dat file? bekim VB.NET 2002/2003 Basics 2 June 16th, 2004 09:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.