• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1378
  • Last Modified:

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)"%>
0
bigtwig
Asked:
bigtwig
  • 5
  • 5
1 Solution
 
kevp75Commented:
you can, however you cannot save it back to the server by simply using the FSO.  From what I have seen you would need to have Word installed on the server, and then a Word object.

Now, as I also undterstand it Word 2007 saves the documents as a type of XML file.  If you know, or can get access to, the actual XML structure you should be able to manipulate that using the XML DOM
0
 
bigtwigAuthor Commented:
What about the Word application object or making a copy of the file, renaming the copy and editing that?
0
 
kevp75Commented:
that requires Word to be installed on the server.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
bigtwigAuthor Commented:
What about just copying the file from Word to an .RTF format?
0
 
kevp75Commented:
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.
0
 
bigtwigAuthor Commented:
Do you have a suggestion?  Thanks.
0
 
kevp75Commented:
I've already given you a suggestion.  see my first post
0
 
bigtwigAuthor Commented:
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.
0
 
kevp75Commented:
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
0
 
bigtwigAuthor Commented:
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>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now