Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.net to Word Question

Status
Not open for further replies.

tjherman

Programmer
Jun 19, 2006
68
US
I have code that uses Interop to create Word documents from within a VS2005 web application. My code either creates a document or opens an existing document in Microsoft Word 2003 to enable a user to make changes and save it.

This all works fine from my development laptop, however when I copy the site to our web server, I have an issue. Initially I got access permission errors but after changing security permission on the DCOM Microsoft Word Document, I got past this. However, now when I run the code from the server, Word never opens to the user. There are instances of winword.exe in the task manager, but the application never opens.

Here's a section of my code that creates a Word document based on a template:

Dim word As New Microsoft.Office.Interop.Word.Application
Dim wobj As Microsoft.Office.Interop.Word.Document
word.Activate()
Try
wobj = word.Documents.Add(fname)
wobj.Activate()
With word
.Visible = True
.Activate()
.ChangeFileOpenDirectory("c:\Proposal\")
.ActiveDocument.SaveAs(sName)
End With

I then go on to replace bookmarks, make other changes and then save the document again.

Once again, when I run my site on my development laptop in VS2005, it all works perfectly. My primary problem is that an instance of Word never opens up to be visible to the user.
 
I read somewhere that it is not recommended to use Word like that in a server environment. Can't remember why, just thought I'd mention it.
 
Office apps don't scale well at all. The application's were meant for a single user on their personal machine, not a server where you open up multiple document instances for multiple web users.

To clarify what you're trying to do, do you want to run Word on the server, or have the server launch a Word app on the client? The latter isn't really possible.
 
You can "open" a Word app on the client-side (MIME type), you can open it in a browser or have an Open/Save prompt come up.
 
My primary problem is that an instance of Word never opens up to be visible to the user.
I suspect your problem is what BoulderBum has mentioned. Any code to launch a Word file will run on the server and therefore the file will open on the server. The user obviously can't see this and no file will ever open for them.

If you want the user to be able to edit a word file, the best method is simply to make it available for download and then provide a mechanism for them to upload it once they've finished with it.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Right, but he's doing some Word automation in his code. I'm unclear on whether he expects the code to run on the client or the server.
 
I want Word to open on the Client's machine, not on the server. All I want to do is be able to open a file from a specific location, allow the user to make edits and then let them save it back to its original location. Doing the download/upload would work but requires the user to do extra work/thinking which I was trying to avoid.

In trying to find alternatives to this, I noticed that if I replace the entire URL in the address line of the browser like this:

\\servername\folder\Proposal.doc

Word opens up in its own window and opens the file off the network server just fine and enables the user to work as I intended.

However, if I try to call this same url with a response.redirect, the browser changes the url to the following and doesn't find anything:


...adding the http stuff and switching the direction of the slashes. Is there another command I can use to tell the browser to open a file from its original location (not prompting for me to download, placing the file in a temp folder).

Bottomline, I just want to open a Word document from its original location in Word on the client's PC, enabling the user to just click save to save any changes they make back to the original source.

Thanks!
 
Bottomline, I just want to open a Word document from its original location in Word on the client's PC, enabling the user to just click save to save any changes they make back to the original source.
That's not possible (or not easily anyway) due to web applications being stateless. The server has no concept of the client (apart from requests that it gets to server a page) and the client has no concept of the server (it simply displays whatever HTML it is sent).

Your best bet for a web application is to go with the upload/download approach.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
You might could try doing this with JavaScript and ActiveX. Make sure that the document is on a shared (possibly mapped too) drive with Read/Write access for your users. Then try this...


I have not done this before, so not sure if it will work or not, plus you'll need to pass your document name/location from the server to JS, but that isn't very hard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top