Bookmark is not found in the document

Hi Stanislav,

Thanks for sharing the details. I have tested your code and have faced the exception “Object reference not set to an instance of an object.”.
I have tried to understand your query and based on my understanding you do not want to delete the contents of inner bookmark. Please confirm.
In this case, according to shared document bookmarks start and end nodes are as follow:

Start : START111634388897195832833F : First Bookmark Start
Start : START110634388897141927273F : Second Bookmark Start
End : START110634388897141927273F : Second Bookmark End
Start : START112634388897235519825F : Third Bookmark Start
End : START111634388897195832833F : First Bookmark End
End : START112634388897235519825F : Third Bookmark End

The third BookmarkEnd is after first BookmarkEnd node, so there may be contents between these two nodes. What should be the output document in this case? You may get the concept of removing node between bookmarks from code share at this link.
I have executed the following code (Call ClearBookmark twice for each bookmark) and have not found any issue with output document. Please see the attached image.

Document doc = new Document(MyDir + "temp.doc"); 
doc.Unprotect();
Bookmark AddendumApprovedBookmark = doc.Range.Bookmarks["START111634388897195832833F"];
Bookmark AddendumBookmark = doc.Range.Bookmarks["START110634388897141927273F"];
Bookmark AddendumSignatureBookmark = doc.Range.Bookmarks["START112634388897235519825F"];
ClearBookmark(AddendumApprovedBookmark, doc);
ClearBookmark(AddendumApprovedBookmark, doc);
ClearBookmark(AddendumBookmark, doc);
ClearBookmark(AddendumBookmark, doc);
ClearBookmark(AddendumSignatureBookmark, doc);
ClearBookmark(AddendumSignatureBookmark, doc);
doc.Save(MyDir + "AsposeOut.doc");

I have attached the output document with this post. It would be great if you please modify the MS Word document according to your desired output and share it with us. We will share the code according to your requirement.

Hi,

Thank you for the answer and i am sorry for the late reference. We thought a lot about this issue and we came to the conclusion that we should avoid this situation and not to try to resolve it as resolution can cause additional problems. Thank you again for the help.

Thanks,
Stanislav.

Hi Stanislav,

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