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

Free Support Forum - aspose.com

Document.Range.Bookmarks collection returns 1 bookmark for 2 times

Hello.

I'm using Aspose.Words dll version 8.0.0.0 and found an issue with bookmarks.

I've added several bookmarks using MS Word 2007: BM1, BM2, Bookmark3 and BM4. BM1 and Bookmark3 are placed closely. When I open bookmark list within MS word i can see all of them. But when I'm trying to enumerate them using Document.Range.Bookmarks collection BM1 occurs twice but Bookmark3 doesn't appear at all.

You can find test document with bookmarks in attachments.

I use next code block for enumeration:

public void Initialize(string filePath)
{
this.WordDocument = new Document(filePath);
BookmarkCollection bookmarkCollection = this.WordDocument.Range.Bookmarks;
string guidText = null;

foreach (Bookmark mark in bookmarkCollection)
{
guidText = Guid.NewGuid().ToString();

Console.WriteLine("Processing bookmark: {0} {1}", mark.Name, guidText);
mark.Text = mark.Name + guidText;
}
this.WordDocument.Save(@"d:\"+Guid.NewGuid().ToString("B")+".doc");
}

Thanks in advance.

Hi

Thanks for your inquiry. I cannot reproduce the problem using the following code:

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Document doc = new Document(@"Test081\in.doc");

BookmarkCollection bookmarkCollection = doc.Range.Bookmarks;

foreach (Bookmark mark in bookmarkCollection)

{

Console.WriteLine("Bookmark: {0}", mark.Name);

}

Best regards,

Hi, AndreyN.

Have you used attached document where i have such problem?
Cause I still have the same problem. I've recently installed version 8.0.0.0. I think it was 7.* before but I'm not sure. I can't see the version of the product within installation wizard :)

Thanks.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Yes I have used your document for testing. The problem is in your code, when you set bookmark text, all content inside bookmark is deleted and if this bookmark contains other bookmarks it will be deleted as well. Please try using my code with your document.

Best regards,

Thanks for your quick reply.

Yep. If I enumerate bookmarks without setting text it works.
But after I process document with my code (setting text for them) MS word still shows me 4 bookmarks (BM1, BM2, Bookmark3 and BM4).

Thanks.

Also I have another problem :)

I have document with macros and when I load it with the help of Aspose.Words and simply save it behavior of the document changes. All macros don't work.
Should I set some special flags before saving?

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. You should note that you use “live BookmarkCollection”, i.e. if you change the document, this collection can be changed as well. If you try getting BookmarkCollection after processing, you will see the same four bookmarks.

Regarding macro, could you please attach your document with macro here for testing? I will investigate the issue and provide you more information.

Best regards,