Bookmark.Remove raises Exception 'Cannot find bookmark 'OLE_LINK5' in the document.'

Hello,

I’ve got the following exception while trying to remove all bookmarks inside my word document.

Aspose.Words.PleaseReportException: Exception ‘Cannot find bookmark ‘OLE_LINK5’
in the document.’ occured in Aspose.Words for .NET 4.4.0.0.
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.

in գ.ട.ദ(Node ࠅ, String ണ)
in
Aspose.Words.Bookmark.get_BookmarkEnd()
in
Aspose.Words.Bookmark.Remove()

My code does that:

For Each Bk As Words.Bookmark In Me.Range.Bookmarks
Bk.Remove()
Next

Only one bookmark fails (“OLE_LINK5”).

Same code is working fine with other documents, so I have attached the specific document that raises the exception. Please help.

Best regards,
Pascal.

Hi
Thanks for your inquiry. I can’t reproduce your problem on my side. I used the following code to remove all bookmarks from document.
VB

Dim doc As Document = New Document("exceptionbookmark.doc")
Dim count As Integer = doc.Range.Bookmarks.Count
Dim i As Integer = 0
For i = 0 To count - 1
doc.Range.Bookmarks(0).Remove()
Next
doc.Save("out.doc")

C#

Document doc = new Document(@"387_104496_skaal\in.doc");
int count = doc.Range.Bookmarks.Count;
for (int i = 0; i < count; i++)
{
    doc.Range.Bookmarks[0].Remove();
}
doc.Save(@"387_104496_skaal\out.doc");

I use the latest version of Aspose.Words (4.4.2.0).
Best regards.

Hello,

I checked my problem : I am still seeing these exceptions, however, if I save the word document to a file before starting to delete bookmarks, I don’t have any exceptions.

In other words this works:

Me.Save("C:\temp\somefile.doc")
For IdxBx As Integer = 0 To Me.Range.Bookmarks.Count - 1
Me.Range.Bookmarks(0).Remove()
Next

This raises an exception with the last bookmarks of the doc file:
’ Me.Save("C:\temp\somefile.doc")

For IdxBx As Integer = 0 To Me.Range.Bookmarks.Count - 1

Me.Range.Bookmarks(0).Remove()

Next

Maybe some cleanup with bookmarks occurs during save? That explains why you couldn’t reproduce the problem.

As a workaround I am saving to a memory stream, which solves my problem ; if you need more information I can help.

Best regards,
Pascal.

Hi

Could you try using the latest version of Aspose.Words? I can’t reproduce your problem using Aspose.Words v4.4.2.0.

This version of Aspose.Words is available for download from here.

Best regards.

Hello,
I tested with v4.4.2.0 for .net 2.0 and got the same results : the last bookmarks of the file, all named (“OLE_LINKxx”) cannot be deleted. However, saving the document prior deleting bookmarks solves the problem.

Here’s my workaround:

Dim memStream As New MemoryStream()
Me.Save(memStream, Words.SaveFormat.Doc)
memStream.Close()
For IdxBx As Integer = 0 To Me.Range.Bookmarks.Count - 1
Try
Me.Range.Bookmarks(0).Remove()
Catch ex As Exception
Msgbox(ex.description)
End Try
Next

The document I generate is quite big (100+pages) and complex (lot of sections and styles) , and I do node manipulation to handle field codes evaluation; therefore it is possible the root cause comes from my code.
Best regards,
Pascal Brunot.

Hi
It is nice that you found workaround independently. Could you please create sample application that will allow me to reproduce this problem? I will investigate this and try to help you.
Best regards.