none
Updating Table of Contents, Word 2007 RRS feed

  • Question

  • Hello all,

    I’ve seen several posts on this subject but am confused on the final solution (??), if any.  On this forum (http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/29199b44-f033-466a-a471-6bdcfeb47e41/) Zeyad says to:

    ·     Set the dirty attribute to have a value of true within the fldChar element

    • Set the upateFileds element in Settings.xml to be true

    How can this be done using the SDK?  Also, after Zeyad’s answer, some posts were made that Word 2007 does not update content of TOC on open…is this true?

    Our issue with the TOC is that it does not update on open even though the page numbers are all up to date.  Is there something we can do using the SDK that will update the TOC as well on open?  If not, is our final resort to use Word Automation Services?   

    Thanks in advance for any information!!!

     

     

     

     

    Tuesday, July 20, 2010 2:44 PM

All replies

  • Hi,

    As you already know that Open XML SDK can't update the TOC automatically, however, you can set the dirty attribute to let Word handle that.  You can manually set them in a document and then analyze the document using Document Reflector tool in Open XML SDK Productivity Tool to see how to generate it programmatically

    http://social.microsoft.com/Forums/en-US/Offtopic/thread/ea9e9dcd-59e5-4c18-8b30-4b4037c2ea85

    Thanks,
    Ankush


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Online Community Support
    Monday, July 26, 2010 9:16 PM
  • Hello Ankush and thank you for responding....

    I went to the link you provided and downloaded the docx.  I looked at it using my reflector but I could not find anything that dealt with updating or setting a field character to dirty.  So I kept searching and was able to find something at this link:  http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/442b8c06-ab3b-428c-9271-f72d5769a083.  It outlined the UpdateFieldsOnOpen and this worked for updating the TOC...but only after some dialogs came up which the user will have to answer.  From everything I've seen, this is the only way it will work without having to use automation, sharepoint, macros or an addin.  Hopefully I'm on the right track here; any input would be appreciated!

    Also, if you could please, I'm still a little confused on what and how the setting the dirty attribute on field characters works in a document (and how to go about this using the sdk) and lastly, could you please explain how to set both the UpdateFieldsOnOpen and the Dirty Attribute for the Field Character manually in a document.

    Thank you for all your help :)

    Tuesday, July 27, 2010 4:30 PM
  • Hi,

    Basically it requers you to do:

    1. Set the dirty flag for all fldChar related to TOC
    <w:fldChar w:fldCharType="begin" w:dirty="true" />

    2. Set the UpdateField which is  the child element of w:settings in the settings.xml/

    Thanks
    Ankush


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Online Community Support
    Thursday, September 2, 2010 1:40 AM
  • Hello Ankush,

    Thanks you for responding...I appreciate it. 

    I was able to find how to set #2 up using the SDK 2.0 (see below).  It now comes up with a dialog for updating.  I'm assuming that there is no way to just update and not have the dialog, correct? 

    MyDoc.MainDocumentPart.DocumentSettingsPart.Settings.PrependChild(new UpdateFieldsOnOpen() { Val = true });

     

     

    Also, I could not find out where and how to set #1 using SDK 2.0....any information would be greately appreciated!

    Thank you !!

    Thursday, September 2, 2010 9:25 PM
  • Hi,

    I suggest to use OpenXMLSDK tool. Set the flag in XML and then use this tool to see the code. Basically you should set the dirty flag for all fldChar related to TOC.

    Thanks
    Ankush

    Friday, September 24, 2010 4:57 PM
  • Hello Ankush,

    Thank you for responding...

    Just so I understand you:  You are saying to convert a TOC document to xml and set all characters related to TOC with a dirty flag and then convert the xml back into a document and then use the tool?  I will go ahead and try it...and update on it.  I do use the OpenXMLSDK tool quite a bit; it is quite helpful though at times fustrating with all the extra code.

    Thanks!!

     

    • Proposed as answer by Ankush_Bhatia Wednesday, October 13, 2010 11:06 AM
    • Unproposed as answer by Ankush_Bhatia Wednesday, October 13, 2010 11:06 AM
    Tuesday, September 28, 2010 3:04 PM
  • Hi,

    Basically there are 2 ways to do it as I explained:

    -> You can set the each TOC's field as dirty (w:dirty="true") and it will update when the document is opened.
    -> If you have many fields you can update the settings in your document so that all fields are updated when the document is opened
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <w:settings xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    <w:updateFields w:val="true" />
    </w:settings>

    However, these both have the downside of a confirmation dialog appearing when the document is opened that says "This document contains fields that may refer to other files. Do you want to update the fields in this document?"

    Once you set the flag in the document (lets do it manually first), open the document in the SDK tool and have a look at the C# code so that you can use it in your application.

    Thanks,
    Ankush


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Online Community Support
    • Proposed as answer by Ankush_Bhatia Wednesday, October 13, 2010 11:06 AM
    Wednesday, October 13, 2010 11:06 AM