Search code examples
vstoversioningcpu-word

Where best to store a version number in Word document?


I have a VSTO Add-In that fills a specific Word template document with data from a third party software. The trick here is that some changes in the script are connected to changes in the document. What I want to do now is to manually store some kind of version number in the document information so I can check in the script if the version of the document fits the version of the script.

I already took a look here but there are too many possibilities and I don't just want to pick any random object. I need to store it somewhere where it doesn't get changed. Where would you recommend to store such a value?

edit: the version number has to be set manually because not every change of the document affects the script.


Solution

  • You have three options:

    1. Document property - can be displayed in a document by using a DocProperty field but can be viewed and easily changed by the user.
    2. Document variable - an old school method but still valid. Can be displayed in a document by using a DocVariable field but can only be added, or the value changed, by using code.
    3. Custom XML Part - can be displayed in a document by mapping to a content control which can allow the value to be changed by the user. If not mapped can only be changed using code, but not as simply as a document variable.