Aspose.Words.Examples.CSharp.Programming_Documents.Working_With_Document.DocumentBuilderInsertElements.InsertTableOfContents C# (CSharp) Method

InsertTableOfContents() public static method

public static InsertTableOfContents ( string dataDir ) : void
dataDir string
return void
        public static void InsertTableOfContents(string dataDir)
        {
            // ExStart:DocumentBuilderInsertTableOfContents
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a table of contents at the beginning of the document.
            builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");

            // Start the actual document content on the second page.
            builder.InsertBreak(BreakType.PageBreak);

            // Build a document with complex structure by applying different heading styles thus creating TOC entries.
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

            builder.Writeln("Heading 1");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

            builder.Writeln("Heading 1.1");
            builder.Writeln("Heading 1.2");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

            builder.Writeln("Heading 2");
            builder.Writeln("Heading 3");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

            builder.Writeln("Heading 3.1");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;

            builder.Writeln("Heading 3.1.1");
            builder.Writeln("Heading 3.1.2");
            builder.Writeln("Heading 3.1.3");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

            builder.Writeln("Heading 3.2");
            builder.Writeln("Heading 3.3");

            doc.UpdateFields();
            dataDir = dataDir + "DocumentBuilderInsertTableOfContents_out.doc";
            doc.Save(dataDir);
            // ExEnd:DocumentBuilderInsertTableOfContents
            Console.WriteLine("\nTable of contents using DocumentBuilder inserted successfully into a document.\nFile saved at " + dataDir);
        }
        public static void InsertOleObject(string dataDir)