Clear text In Bookmark

Hi,
i have this code:
doc.Range.Bookmarks[“BookmarkSarvanRishum”].Text = string.Empty;
And I get the error:
Cannot insert a node of this type at this location
What is the problem??

@naomidu,

Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Thank you, but I found an answer in the forum;
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;

}
:slight_smile:

@naomidu,

Thanks for your feedback. It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

:frowning:
I see that it erases the bookmark, I want only to erase the text in the bookmark

@naomidu,

Thanks for your inquiry. Please ZIP and attach your input Word document here for our reference. We will then provide you more information about your query along with code.

2 posts were split to a new topic: Cannot insert a node of this type at this location - Clearing Bookmark Text