Syncfusion Feedback

Trusted by the world’s leading companies

Syncfusion Trusted Companies

Overview

The Syncfusion .NET Word Library (DocIO) is a feature-rich and high-performance tool that allows users to create and update the table of contents (TOC) in a Word document using C# without relying on Microsoft Word or interop dependencies. Build the TOC based on headings with custom styles. Include page numbers and hyperlinks for easy navigation.

Create and update TOCs in Word documents using C#

This example code shows how to update a table of contents in a Word document using the Syncfusion .NET Word Library with just a few lines of code in C#.

using Syncfusion.DocIO; 
using Syncfusion.DocIO.DLS; 
using Syncfusion.DocIORenderer; 
//Create a new Word document. 
using WordDocument document = new WordDocument(); 
//Add the TOC in the first section. 
IWSection section = document.AddSection(); 
IWParagraph paragraph = section.AddParagraph(); 
string paraText = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company."; 
//Append TOC for heading levels 1 to 3. 
paragraph.AppendTOC(1, 3); 
//Add the first chapter. 
section = document.AddSection(); 
paragraph = section.AddParagraph(); 
paragraph.AppendText("First Chapter"); 
paragraph.ApplyStyle(BuiltinStyle.Heading1); 
section.AddParagraph().AppendText(paraText); 
//Add the second chapter. 
section = document.AddSection(); 
paragraph = section.AddParagraph(); 
paragraph.AppendText("Second Chapter"); 
paragraph.ApplyStyle(BuiltinStyle.Heading2); 
section.AddParagraph().AppendText(paraText); 
//Add the third chapter. 
section = document.AddSection(); 
paragraph = section.AddParagraph(); 
paragraph.AppendText("Third Chapter"); 
paragraph.ApplyStyle(BuiltinStyle.Heading3); 
section.AddParagraph().AppendText(paraText); 
//Update the table of contents. 
document.UpdateTableOfContents(); 
//Save the Word document. 
using FileStream outputFileStream = new FileStream("Result.docx", FileMode.Create, FileAccess.ReadWrite); 
document.Save(outputFileStream, FormatType.Docx);

Key features of tables of contents

Customize TOC entries

Customize the visual appearance of TOC entries, accommodating up to 9 levels of entries.

Custom styles

Define and use custom styles in the TOC, mapping them to specific heading levels instead of relying solely on default heading styles.

Format TOC

Modify the text of TOC entries, change tab leaders, customize heading levels, manage page numbers, add hyperlinks, and more.

Table of figures

Generate a table of captions for figures, tables, charts, and other numbered items using SEQ fields. Additionally, you can create a table of captions without labels and numbers.

Table of contents references

Discover resources from our blog and knowledge base to enhance your efficiency in using tables of contents in Word documents.

How to create and update a table of contents in Word documents

Blog

Create and update a table of contents in Word documents: a step-by-step guide

Changing the tab leader of a table of contents in a Word

Knowledge base

How to change the tab leader of a table of contents in a Word document using C#

Customizing the TOC entry style in a Word document

Knowledge base

How to customize the TOC entry style in a Word document using C#

How to modify the text of TOC entries

Knowledge base

How to modify the text of TOC entries in a Word document

Syncfusion .NET Word Library Resources

Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.

Frequently Asked Questions

Yes, you can customize the entries of a TOC in a Word document using the .NET Word Library.

Yes, you can insert multiple TOCs in a single Word document using the .NET Word Library.

Yes, similar to Word documents, you can navigate to the corresponding headings from the TOC in the PDF converted from a Word document.

Yes, the .NET Word Library generates TOCs with hyperlinks and page numbers.

Yes, the .NET Word Library supports creating hierarchical TOCs with multiple levels of headings.

You can access it through the Syncfusion.DocIORenderer.Net.Core NuGet package. Detailed code samples and video tutorials are available in the documentation.

Our Customers Love Us

Having an excellent set of tools and a great support team, Syncfusion® reduces customers’ development time.
Here are some of their experiences.

Rated by users across the globe

Want to create, View, and edit Word documents in C# or VB.NET?

Start a free 30-day evaluation today!
DOWNLOAD FREE TRIAL

No credit card required.

Mobile Free Evaluation Section

Awards

Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion® is proud to hold the following industry awards.

Scroll up icon