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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback


Trusted by the world’s leading companies

Overview

Bookmarks in a Word document serve as placeholders that can be utilized to mark particular locations or content. The Syncfusion .NET Word Library (DocIO) enables users to add and remove bookmarks in C#. Moreover, users can programmatically retrieve, 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.


How to add bookmarks in a Word document using C#

  1. Install NuGet package: Install the Syncfusion.DocIO.Net.Core NuGet package in your project.
  2. Create Word document: Initialize the WordDocument object and call the EnsureMinimal method to add a new section and paragraph.
  3. Add bookmark start: Insert a bookmark start named “Northwind” using the AppendBookmarkStart method.
  4. Add content to bookmark: Use the AppendText method to add text in the paragraph.
  5. Add bookmark end: Add a bookmark end named “Northwind” using the AppendBookmarkEnd method.
  6. Save Word document: Save the WordDocument object to the FileStream object.

Here is an example of how to add a bookmark in a Word document in C# using the Syncfusion .NET Word Library.

//Create an instance of WordDocument.  
using WordDocument document = new WordDocument(); 

//Add a new section and paragraph in the document.  
document.EnsureMinimal(); 

//Get the last paragraph.  
IWParagraph paragraph = document.LastParagraph; 

//Add a new bookmark start in the paragraph with the name "Northwind." 
paragraph.AppendBookmarkStart("Northwind"); 

//Add text between the bookmark start and end in the paragraph. 
paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases."); 

//Add a new bookmark end in the paragraph with the name "Northwind". 
paragraph.AppendBookmarkEnd("Northwind"); 

//Add text after the bookmark end.  
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."); 

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

Manage bookmarked content

Delete bookmarked content

Fetch and delete bookmarked content in a Word document with just a few lines of code.

Replace bookmarked content

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




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

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon