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.
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);
Fetch and delete bookmarked content in a Word document with just a few lines of code.
Fetch and replace bookmarked content with text, document elements, or an entire Word document.
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.