VB code to remove the content of a bookmark without affecting other bookmark nodes is included in this forum post. Has anyone written this code in C#? If there’s a C# version written and tested, it would save me some work. Thanks.
Hi Dexter,
Thanks for your inquiry. I think, you can use the following code to be able to remove all nodes contained between BookmarkStart and BookmarkEnd nodes:
Document doc = new Document(@"C:\Temp\in.docx");
Bookmark bookmark = doc.Range.Bookmarks["bm"];
Node currentNode = bookmark.BookmarkStart;
bool flag = true;
while (currentNode != null && flag)
{
if (currentNode.NodeType == NodeType.BookmarkEnd)
flag = false;
Node nextNode = currentNode.NextPreOrder(currentNode.Document);
currentNode.Remove();
currentNode = nextNode;
}
doc.Save(@"C:\Temp\out.docx");
I hope, this helps.
Best regards,