Hi krishnaramuu,
You may refer to this post for creating TOC: http://openxmldeveloper.org/forums/thread/4680.aspx
I've written some code to add/update the TOC, and recorded screen-casts around using the code:
openxmldeveloper.org/.../exploring-tables-of-contents-in-open-xml-wordprocessingml-documents.aspx
-Eric
i've written code in C# to extract data from db then populate a Word template (using content controls as placeholders). The content controls i am using are for picture and rich-text. i search for the content control using their respective tags and build the content for it. Everything works beautifully!
And then i add a TOC to the template and i get an error at my content control saying "null reference". When i debug i find that the code to find the tag continues again after finding my correct control and then throws this error.
If i remove the TOC from the template, everything works beautifully again. Why is TOC messing up with the tag? It doesn't have a tag of its own....
HELP Please!
Hi sham_b24,
When you insert a TOC into your document, the TOC is placed inside of its own content control. Your code, while properly processing all of the content controls that you have inserted into the document, probably is not written to expect the content control that surrounds the TOC. The content control that contains the TOC has a docPartGallery element with a val of "Table of Contents". You can use this characteristic to modify your code to ignore this content control. Does this solve your problem?
<w:sdt> <w:sdtPr> <w:id w:val="-1750491867"/> <w:docPartObj> <w:docPartGallery w:val="Table of Contents"/> <w:docPartUnique/> </w:docPartObj> </w:sdtPr>