I thought the following would work:
var bod = wordDoc.MainDocumentPart.Document.Body;
foreach (var bookmark in bod.Descendants<BookmarkStart>())
{
bookmark.Remove();
}
foreach (var bookmark in bod.Descendants<BookmarkEnd>())
{
bookmark.Remove();
}
but this corrupts the file.
Try this, it worked on my document.
var bs = wordDoc.MainDocumentPart.Document
.Descendants<BookmarkStart>()
.ToList();
foreach (var s in bs)
s.Remove();
var be = wordDoc.MainDocumentPart.Document
.Descendants<BookmarkEnd>()
.ToList();
foreach (var e in be)
e.Remove();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With