Clear text In Bookmark


#1

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??


#2

@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.


#3

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:


#4

@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.


#5

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


#6

@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.