Welcome to WebmasterWorld Guest from 50.17.79.100

Forum Moderators: ocean10000

Message Too Old, No Replies

Reaing Word using OpenTextFile

I just get nonsense returned

     

Condor12

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

10+ Year Member



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

aspdaddy

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

WebmasterWorld Senior Member 10+ Year Member



openTextFile does not read word documents, you need a component to do this.

Condor12

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

10+ Year Member



Thanks aspdaddy,

I suppose that makes sense, (openTEXTfile!)

Any idea what component I would need?

Thanks

Alan

aspdaddy

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

WebmasterWorld Senior Member 10+ Year Member



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.

snookie

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

10+ Year Member



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?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month