We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Syncfusion Feedback


Trusted by the world’s leading 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#. Build the TOC based on heading and custom styles, including page numbers and hyperlinks for easy navigation.


How to update the Table of Contents in a Word document using C#

  1. Install NuGet package: Install the Syncfusion.DocIORenderer.Net.Core NuGet package in your project.
  2. Open Word document: Create a WordDocument object by passing the FileStream object.
  3. Update Table of Contents: Use the UpdateTableOfContents method of the WordDocument class to update the table of contents.
  4. Save Word document: Save the WordDocument object to the FileStream object.

Here is an example of how to update the table of contents in a Word document in C# using the Syncfusion .NET Word Library (DocIO).

//Load an existing Word document
using FileStream inputDocumentStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using WordDocument document = new WordDocument(inputDocumentStream, FormatType.Docx);

//Update the table of contents
document.UpdateTableOfContents();

//Save the Word document
using FileStream outputDocumentStream = new FileStream("Result.docx", FileMode.Create, FileAccess.ReadWrite);
document.Save(outputDocumentStream, FormatType.Docx);

Customize Table of Contents

Customize TOC entries

Personalize the visual appearance of TOC entries, accommodating customization for up to 9 levels of entries.

Custom styles

Users can define custom styles along with their corresponding heading levels in the TOC, instead of default heading styles.

Format TOC

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




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