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 .Connectio n")
oConn.ConnectionTimeout = 15
oConn.Open "DSN=(dsn_name);UID=sa;PWD =(password );DATABASE =(db)"%>
My connection string is:
<%
Dim oConn
Set oConn = Server.CreateObject("ADODB
oConn.ConnectionTimeout = 15
oConn.Open "DSN=(dsn_name);UID=sa;PWD
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
that requires Word to be installed on the server.
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.
You would need something to interpret the code used in the rtf file.
ASKER
Do you have a suggestion? Thanks.
I've already given you a suggestion. see my first post
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("s cripting.f ilesystemo bject")
newname="NewFiles\" & JobNumber & ".rtf"
fso.CopyFile server.mappath("MasterFile s\source.d oc"), 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.
dim fso,newname
set fso=server.createobject("s
newname="NewFiles\" & JobNumber & ".rtf"
fso.CopyFile server.mappath("MasterFile
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
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
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("Updat e") = "Update" Then
dim fso,newname
set fso=server.CreateObject("s cripting.f ilesystemo bject")
newname="JobExceptions\"&R equest.Que ryString(" JobNumber" )&".rtf "
fso.CopyFile server.mappath("MasterFile s\tower.do c"),server .mappath(n ewname)
set fso=nothing
set objFSO = Server.CreateObject("Scrip ting.FileS ystemObjec t")
set File = objFSO.OpenTextFile(newnam e, 1)
sFileData = File.ReadAll
File.Close
Set File = objFSO.OpenTextFile(newnam e, 2)
File.Write(sFileData)
File.Close
End If
%>
<html>
<head><title>This is a test</title></head>
<body>
Previous file is: <a href="<%=newname%>"><%=new name%></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>
<%
if Request.QueryString("Updat
dim fso,newname
set fso=server.CreateObject("s
newname="JobExceptions\"&R
fso.CopyFile server.mappath("MasterFile
set fso=nothing
set objFSO = Server.CreateObject("Scrip
set File = objFSO.OpenTextFile(newnam
sFileData = File.ReadAll
File.Close
Set File = objFSO.OpenTextFile(newnam
File.Write(sFileData)
File.Close
End If
%>
<html>
<head><title>This is a test</title></head>
<body>
Previous file is: <a href="<%=newname%>"><%=new
<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>
ASKER