DocumentBase.TablesOfContents Property
Visual Studio 2012
Gets a TablesOfContents collection that represents the tables of contents in the document.
Assembly: Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)
Property Value
Type: TablesOfContentsA TablesOfContents collection that represents the tables of contents in the document.
The following code example adds two paragraphs to the document and assigns the Heading 1 and Heading 2 styles to the paragraphs. The code then creates a table of contents at the insertion point that includes only paragraphs styled Heading 1. To use this example, run it from the ThisDocument class in a document-level project.
private void DocumentTablesOfContents() { this.Paragraphs[1].Range.InsertParagraphBefore(); this.Paragraphs[1].Range.InsertParagraphBefore(); this.Paragraphs[1].Range.Text = "Heading 1"; this.Paragraphs[2].Range.Text = "Heading 2"; object Style1 = Word.WdBuiltinStyle.wdStyleHeading1; this.Paragraphs[1].set_Style(ref Style1); object Style2 = Word.WdBuiltinStyle.wdStyleHeading2; this.Paragraphs[2].set_Style(ref Style2); object HeadingLevel = 1; this.TablesOfContents.Add(this.Application.Selection.Range, ref missing, ref HeadingLevel, ref HeadingLevel, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); }
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.