2
votes

I create new word document using DocumentFormat.OpenXml. I load template document in which located the table of content and the table with picture logo. I append other content using c# code for this template. I send this document to user.

When user get this document and open it - the table of contents not update. I found the resolve this problem. I add to my code

  • mainPart.DocumentSettingsPart.Settings.Append(new UpdateFieldsOnOpen() { Val = true });

But when user will get the document and will open it he get the message from MS Word "You wanna update fields?".

Is there any other way to generate table of contents or update table of contents without any message to user?

2

2 Answers

0
votes

I got answer for my question: http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/7f53a939-f50e-423d-90fa-1f3c58945a6e

The cause of what you're seeing is a security measure that was introduced a few years ago. Possibly, you can suppress the message by using the Registry entry described in the following KB article. You need to be aware, however, that this could reduce system security.

The following blog article describes the "correct" way to update the TOC: http://support.microsoft.com/kb/330079

Other than that, the only thing available would be a macro embedded in the document or in an addin that uses automation to force the fields to update.

0
votes

We have had a long discussion in similar thread regarding generating Table Of Content (TOC) with help of OpneXML SDK 2.0. And there is a detailed solution explaining how it could be achieved. Look at this thread for details: How to generate Table Of Contents using OpenXML SDK 2.0?