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

Free Support Forum - aspose.com

Exception: Cannot find bookmark

I received the following error in my application. The document appears to have the CC bookmark in there, so I don’t know what’s wrong here. Can you please help me figure this out.
Thank you

Thanks for your request. Could you please provide me code that will allow me to reproduce this issue? I tried to use the following code and all works fine on my side.

Document doc = new Document(@"Test170\11428.doc");
doc.Range.Bookmarks["CC"].Text = "test";

I use the latest version of Aspose.Words for testing.
Best regards.

Here is the exception message that I received

Aspose.Words.PleaseReportException: Exception 'Cannot find bookmark 'CC' in the document.' occured in Aspose.Words for .NET For free technical support, please post this error and the file in the Aspose.Words Forums http://www.aspose.com/forums/ShowForum.aspx?ForumID=75. at ՠ.ჩ.ჰ(Node ࠺, String ჭ) at Aspose.Words.Bookmark.get_BookmarkEnd() at Aspose.Words.Bookmark.Remove() at MTASP2Utilities.MTASP2TemplateMerger.MergeTemplates() 

The code that is throwing the error is as follows

for (int i = _OutputDoc.Range.Bookmarks.Count - 1; i >= 0; i--)

Thanks for additional information. If you need to remove all bookmarks from document then you can use the following code:


Also you can modify your code:

int count = doc.Range.Bookmarks.Count;
for (int i = 0; i < count; i++)

Hope this helps.
Best regards.

I changed the code to _OuputDoc.Range.Bookmarks.Clear() & it still threw the same error.
Why should this line of code even think there’s a CC bookmark? How would I investigate this.
Thanks much

I can’t reproduce this issue on my side. Range.Bookmarks.Clear() works fine on my side. Maybe you attached a wrong document.
Best regards.