Welcome to WebmasterWorld Guest from 54.196.214.35

Forum Moderators: ocean10000

Message Too Old, No Replies

Reaing Word using OpenTextFile

I just get nonsense returned

     
11:03 am on Apr 8, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 17, 2003
posts:49
votes: 0


Hi,

I'm trying to read the text from a Word file using ASP and OpenTextFile then add it to the end of a new word document that has some text already.

When I do this the added Word info comes out as?! etc etc...

I used the code below

Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateUseDefault=-1
filedir=Server.MapPath("../" & Filenumb(1))
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(filedir) Then
Set filetxt = filesys.OpenTextFile(filedir, ForReading, False, TristateUseDefault)
cvtext=filetxt.ReadAll
filetxt.Close

Set wfile = filesys.CreateTextFile(filedir, True)
wfile.Write (thetext)
wfile.close

I also tried just adding the text to the end of the Word file but there was no change to the file, (permissions set to allow write on the folder)

Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateUseDefault=-1
filedir=Server.MapPath("../" & Filenumb(1))
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(filedir) Then
Set filetxt = filesys.OpenTextFile(filedir, ForAppending)
filetxt.writeline("Test")
filetxt.Close

It seems to work with txt files but not Word.

Any ideas?

Alan

12:35 pm on Apr 8, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:2162
votes: 0


openTextFile does not read word documents, you need a component to do this.
12:44 pm on Apr 8, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 17, 2003
posts:49
votes: 0


Thanks aspdaddy,

I suppose that makes sense, (openTEXTfile!)

Any idea what component I would need?

Thanks

Alan

9:01 am on Apr 9, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:2162
votes: 0


The component is the Word.Application BUT take a look at this first.
INFO: Considerations for Server-Side Automation of Office [support.microsoft.com]

There are some links at the bottom for 3rd party component vendors.

You could also consider client-side automation of Word if its an intranet or extranet or controlled environment.

3:03 pm on Apr 9, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 4, 2003
posts:94
votes: 0


I think to use the Word.Application that you'll need to have Word on the server that is handling the file. We only ever handled client-side using VBScript. I dunno but you maybe able to use wordpad components to handle the file?