If your using the Microsoft.Office.Interop.Word library there is an event you can subscribe too:
Microsoft.Office.Interop.Word.Application wordApp =
new Microsoft.Office.Interop.Word.Application();
wordApp.DocumentBeforeClose +=
new ApplicationEvents4_DocumentBeforeCloseEventHandler(
wordApp_DocumentBeforeClose);
...
private void wordApp_DocumentBeforeClose(Document Doc, ref bool Cancel)
{
// Do your thing
}
Edit:
To take care of the file lock ==> take a look at this post. As you can see there are a few things done in the DocumentBeforeClose:
- Check if the document is saved. If not ==> ask where to save it and do it yourself.
- Close the document yourself
- Close Word
After these things are taken care of, you can do your stuff. The lock should be released.