Link to home
Start Free TrialLog in
Avatar of bigtwig
bigtwig

asked on

Open Word document from ASP page using FileSystemObject, then edit it on screen

I have a bunch of Word documents on a Web Server in a separate folder.  All of my users do not have access to the Web Server directly, but they should have access to it from my Intranet application.  I want to be able to display a list of the Word documents in the folder in a dropdown box and have the user select a file.  Then the would enter a job number and click submit.  The .asp page should use a FileSystemObject to open the file selected, Save it as JobNumber.doc and then open that file for edit on the screen.  Can I do that?

My connection string is:
 <%      
Dim oConn
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.ConnectionTimeout = 15
oConn.Open "DSN=(dsn_name);UID=sa;PWD=(password);DATABASE=(db)"%>
ASKER CERTIFIED SOLUTION
Avatar of kevp75
kevp75
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bigtwig
bigtwig

ASKER

What about the Word application object or making a copy of the file, renaming the copy and editing that?
that requires Word to be installed on the server.
Avatar of bigtwig

ASKER

What about just copying the file from Word to an .RTF format?
yes, you can do that manually.  However you would still need a way to read in the formatting, which you cannot do with a normal textarea.

You would need something to interpret the code used in the rtf file.
Avatar of bigtwig

ASKER

Do you have a suggestion?  Thanks.
I've already given you a suggestion.  see my first post
Avatar of bigtwig

ASKER

This works perfectly AND it allows me to save it back to the server, so I'm not sure what you're saying the limitation is:

 dim fso,newname
 set fso=server.createobject("scripting.filesystemobject")
 newname="NewFiles\" & JobNumber & ".rtf"
 fso.CopyFile server.mappath("MasterFiles\source.doc"), server.mappath(newname)
 set fso=nothing

I've decided to rename the file to an RTF, so I've eliminated any hurdle the Word on the server or Word licensing may have.

Now I need code that will build me a combo box of all the .doc files in \MasterFiles, let me select one, create newname as an .RTF and then open the RTF for edit on an ASP page.  Thanks.
all that you've posted is simply copying the file.  There is nothing there to indicate you are editting the file

If you still think you can load an RTF file into a textarea in order to edit it, good luck, because as I've already stated it cannot be done in a normal textarea, as it cannot render the formatting
Avatar of bigtwig

ASKER

I think this code will do what I want it to do.  It seems that the FileSystemObject is very friendly with the OpenTextFile commands for Read/Write.

<%
if Request.QueryString("Update") = "Update" Then
      
   dim fso,newname
   set fso=server.CreateObject("scripting.filesystemobject")
   newname="JobExceptions\"&Request.QueryString("JobNumber")&".rtf "
   fso.CopyFile server.mappath("MasterFiles\tower.doc"),server.mappath(newname)
   set fso=nothing
      
   set objFSO = Server.CreateObject("Scripting.FileSystemObject")
      
   set File = objFSO.OpenTextFile(newname, 1)
   sFileData = File.ReadAll
   File.Close
      
   Set File = objFSO.OpenTextFile(newname, 2)
   File.Write(sFileData)
   File.Close
End If
%>

<html>
<head><title>This is a test</title></head>
<body>
Previous file is: <a href="<%=newname%>"><%=newname%></a>

<form name="form1" method="get">
<table>
<tr>
 <td>Job Number: <input type="text" name="JobNumber" size=20></td>
 <td><input type="submit" name="Update" value="Update"></td>
</tr>
</table></form>
</body></html>