Syncfusion Feedback

Trusted by the world’s leading companies

Syncfusion Trusted Companies

Overview

Bookmarks in a Word document serve as placeholders that can mark particular locations or content. The Syncfusion .NET Word library (DocIO) enables users to add and remove bookmarks in C#. Users can programmatically extract, edit, and delete bookmarked content in C#, providing a versatile method to identify and locate content within a Word document without relying on Microsoft Word or interop dependencies.

Add bookmarks in a Word document using C#

This example code shows how to add bookmarks in a Word document using the Syncfusion .NET Word library with just a few lines C# code.

  1. using Syncfusion.DocIO;
  2. using Syncfusion.DocIO.DLS;
  3. //Create an instance of WordDocument
  4. using WordDocument document = new WordDocument();
  5. //Add a new section and paragraph in the document
  6. document.EnsureMinimal();
  7. //Get the last paragraph.
  8. IWParagraph paragraph = document.LastParagraph;
  9. //Add a new bookmark at the start of the paragraph with the name "Northwind"
  10. paragraph.AppendBookmarkStart("Northwind");
  11. //Add text between bookmarks at the start and end of the paragraph.
  12. paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access.");
  13. //Add a new bookmark at the end of the paragraph with the name "Northwind"
  14. paragraph.AppendBookmarkEnd("Northwind");
  15. //Add text after the bookmark ends
  16. paragraph.AppendText(" Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.");
  17. //Save the Word document in DOCX format
  18. using FileStream outputStream = new FileStream("Result.docx", FileMode.Create, FileAccess.ReadWrite);
  19. document.Save(outputStream, FormatType.Docx);

Key functions of bookmarks in Word documents

Add and remove bookmarks

Easily create new bookmarks at the start and end of the Word document, programmatically. Also, remove the existing bookmarks from the Word document.

Extract bookmarked content

Extract bookmarked content from the Word document programmatically, including content within the body and tables.

Delete bookmarked content

Delete bookmarked content between bookmark start and end tags in the Word document.

Replace bookmarked content

Fetch and replace bookmarked content with text, document elements, or an entire Word document.

Explore references of bookmarks in Word documents

Check out our knowledge base articles to efficiently work with bookmarks in Word documents.

How to insert nested bookmarks in a Word

Knowledge base

How to insert nested bookmarks in a Word document using C#

How to insert bookmark for specific text

Knowledge base

How to insert a bookmark for specific text in a paragraph in a Word document using C#

Inserting HTML within bookmark in Word

Knowledge base

How to insert HTML content within a bookmark in a Word document using C#

How to replace bookmark content in a Word document

Knowledge base

How to replace bookmark content in a Word document with content from another document in C#

How to add table at bookmark location

Knowledge base

How to add a table at a bookmark location in a Word document using C#

Retrieving section number of a specific bookmark

Knowledge base

How to retrieve the section number of a specific bookmark in a Word document using C#

Syncfusion .NET Word Library Resources

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

Frequently Asked Questions

Yes, you can extract the collection of bookmarks available in the Word document and also find the bookmark by name using the .NET Word library (DocIO).

Yes, the .NET Word Library (DocIO) extracts bookmarked contents that traverse multiple sections.

Without the end tag, the bookmark is incomplete and will not be recognized as valid. To create a valid bookmark, make sure to add start and end tags.

No, the Word document does not support adding two bookmarks with the same name, and the .NET Word library (DocIO) does not either.

Yes, you can extract the bookmarked content from the Word document and then save it as a separate Word document programmatically using the .NET Word library (DocIO).

You can access it through the Syncfusion.DocIO.Net.Core NuGet package. Detailed code samples are available in the documentation, facilitating seamless integration.

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
Chat with us