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.
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.
- using Syncfusion.DocIO;
- using Syncfusion.DocIO.DLS;
- //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 at the start of the paragraph with the name "Northwind"
- paragraph.AppendBookmarkStart("Northwind");
- //Add text between bookmarks at the start and end of the paragraph.
- paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access.");
- //Add a new bookmark at the end of the paragraph with the name "Northwind"
- paragraph.AppendBookmarkEnd("Northwind");
- //Add text after the bookmark ends
- 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);
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 from the Word document programmatically, including content within the body and tables.
Delete bookmarked content between bookmark start and end tags in the Word document.
Fetch and replace bookmarked content with text, document elements, or an entire Word document.
Check out our knowledge base articles to efficiently work with bookmarks in Word documents.
Knowledge base
Knowledge base
Knowledge base
Knowledge base
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
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.
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.