This article describes how to remove bookmark in Word using C#. You will get details on setting up the development environment, step-by-step instructions, and sample code showing how to remove bookmark in Word using C#. You can also enhance the given sample code to create a custom output document.
Steps to Remove Bookmark from Word DOC using C#
- Set up the IDE to use Aspose.Words for .NET to remove bookmarks
- Load the source Word file that contains bookmarks into the Document object
- Collect the names of all the bookmarks in the document
- Find the internal hyperlinks that point to these bookmarks
- Convert those hyperlinks into plain text and keep the link text
- Remove all the bookmarks and keep the bookmarked text as it is
- Save the updated Word file without bookmarks
These steps describe how to remove all bookmarks in Word using C#. Load the source Word file, collect the names of all its bookmarks, and find the internal hyperlinks that point to them. Convert these hyperlinks into plain text so that no broken links are left behind, remove all the bookmarks while keeping their text, and save the output Word file.
Code to Delete Bookmark in Word using C#
This code demonstrates how to delete a bookmark in Word using C#, including those in headers and footers. Check the bookmark name in both loops so that only that bookmark and the links pointing to it are removed. Note that the code also removes the hidden “_Toc” bookmarks used by the table of contents, so skip the names that start with “_Toc” if you want to keep the table of contents links working.
This article teaches the process of removing bookmarks and the internal links that point to them while keeping the text. To remove links from a Word file and keep the link text in normal format, refer to the article Remove hyperlinks from Word using C#.