We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Bookmark.Text does not remove the content correctly using C#

In the template there are two bookmark called “Heir” and “possibleheir” and we are removing only the content of bookmark when bookmark is “Heir” so as per the code it should only remove the content of bookmark “Heir” and should leave bookmark called “possibleheir” as it is but when statement highlighted in yellow section is executed It removes another bookmark called “possibleheir” and It should not be.

public void checkBookMark(Document docMain)
{
BookmarkCollection oBookmarkCollection = docMain.Range.Bookmarks;
//Fetching all bookmarks

foreach (Bookmark bookmark in oBookmarkCollection)
{
if (bookmark.Name != “_GoBack”)
{
BookmarkStart bookmarkStart = bookmark.BookmarkStart;
BookmarkEnd bookmarkEnd = bookmark.BookmarkEnd;
if (bookmark.Name == “Heir” || bookmark.Name != “possibleheir”)
{
bookmark.Text = “”;
//once this line is executed It removes bookmark called ‘possibleHeir’
}
}
}
}

Other Information:

  1. Aspose Library & version: Aspose.Words 19.7.0.0 (Aspose.Words for .NET)
  2. Programming language: C#

I am not able to upload word template here. Can you please share your e-mail or suggest some other way so that I can send you the word template document

I am your paid customer. Please helpTest_Bookmark - Complaint.zip (20.7 KB)

@johnkaltz

We suggest you please try the latest version of Aspose.Words for .NET 20.2. Hope this helps you.

If you still face problem, please ZIP and attach your input Word document here for testing. We will investigate the issue and provide you more information on it.

Uploaded document in Zip file. Please check.
Currently I am using 19.7.0.0.

@johnkaltz

We have tested the scenario using the latest version of Aspose.Words for .NET 20.2 and have not found the shared issue. So, please use Aspose.Words for .NET 20.2.

I have updated the Aspose.Words DLL and it resolved the issue.
Thank you.

@johnkaltz

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.