0
votes

I have a requirement to open and manage a Word document, stored on the file system, from .NET code. In particular, I want to be able to show a dialog and possibly submit it to a server when the user closes the Word document in question.

Having experimented and searched a bit, I am not sure how to proceed with this. Possibilities appear to include:

  1. Using Process.Start and listening for the Exited event.
  2. Using Microsoft.Office.Interop.Word and then starting the doc through that and listening for the DocumentBeforeClose event.

Neither of these seems to entirely solve the problem, however. (1) because there will only be one Word process running for multiple open documents and the Exited event received will not necessarily correspond to the actual document that my code was responsible for opening. And (2) because it doesn't cope with the case in which Word crashes, and it's a hassle to get the tidying up of those COM objects right.

If anyone has an idea how to proceed with this, or an article that would help, I would be grateful.

1

1 Answers

1
votes

I've done something similar to this in a previous job except that it was from a web page. What I did is that the document was downloaded to the local computer from the web site and there was a new toolbar in word. For the new toolbar, I think it's was with macro so the coding is in VBScript. I had a couple of buttons inside this toolbar to submit the document to the server and update the version in the database, save the document locally. In fact, since you can connect to database and use FSO in VBScript, you can do whatever you want including validating if the document is currently open by someone else, etc.

It's just a suggestion that is working. Maybe you can use a part of this solution and mix it with your own to find a satisfying result.

Good luck