We solved this using a workaround:
- Open the file with Aspose.Words
- Set AttachedTemplate
- Save and close the file
- Open the file with Microsoft.Office.Interop.Word
It isn't pretty, but it works.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Our c# UI application is using Microsoft.Office.Interop heavily to integrate Microsoft Office products visually.
We switched from the legacy document formats to the new OOXML document formats.
Now the behaviour for Microsoft.Office.Interop.Word.Document.set_AttachedTemplate() seems to have changed:
it locks the template file
Previously this wasn't the case. In our application, multiple documents get opened, the second document gets the locked file warning now.
How to prevent this?
----------
I traced the filesystem operations using Process Monitor and I can see a difference at the end: dotx has no CloseFile operation at the end, while dot has
dot template gets closed:
dotx template doesn't get closed:
We solved this using a workaround:
It isn't pretty, but it works.