This project has moved and is read-only. For the latest updates, please go here.

Removing Bookmarks

Apr 19, 2016 at 6:43 PM
Edited Apr 20, 2016 at 1:50 AM
I am trying to setup a find and replace system to loop through the bookmarks in a document. The following function locates the bookmark and places the text correctly but for some reason I am unable to figure out the correct syntax to remove the bookmark from the document.

~Function removed as redundant~

I tried using the clearall methods etc etc.

Any help appreciated!


Continued tinkering and realized that the bookmarks collection in documents was merely an internal list collection and removing it from that list would in fact NOT delete it from the document.

As it stands there does not appear to be a native way to delete a bookmark so I am endeavoring to add this functionality.... will post my success here.

~Edit 2 ~

Add this this Bookmarks.cs
public void Delete()
Add this in Paragraph.cs
public void DeleteBookmark(string bookmarkName)
            var bookmark = Xml.Descendants(XName.Get("bookmarkStart", DocX.w.NamespaceName)).Where(x => x.Attribute(XName.Get("name", DocX.w.NamespaceName)).Value == bookmarkName).SingleOrDefault();