I have a WinForms application where I provide versioned links to Word documents. When the user clicks on the links, it opens the Word document. My requirements are when they open the Word document, perform changes, save, and then close the document, to detect that changes have been made and upload a copy with a new version to the database.
I have currently done the following:
ProcessStartInfo psi = new ProcessStartInfo(FilePath) { UseShellExecute = true };
Process process = Process.Start(psi);
process.EnableRaisingEvents = true;
process.Exited += process_Exited;
This seems like it should work well, however, I ran into a few problems:
- The user can simply close the actual document without closing Word and the Exited event will never fire.
- If Word is already open when they click the link to open the document, the Process.Start method returns null.
- My user can close the WinForms application and the Word document may still be left open. This can be problematic because the user may make changes after closing the app and the changes will not be persisted to the database.
Are there any other options I have to achieve my desired results? Has anyone done anything similar and can provide any direction to resolve my issues?
Thanks in advance for any assistance.