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

Last post 11-18-2009, 6:06 AM by AndreyN. 6 replies.
Sort Posts: Previous Next
  •  11-17-2009, 10:41 AM 208361

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

    Attachment: Present (inaccessible)

    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.

     
  •  11-17-2009, 2:23 PM 208399 in reply to 208361

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

    Hi

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

     

    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,


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  11-18-2009, 3:33 AM 208514 in reply to 208399

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

    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.

     
  •  11-18-2009, 4:17 AM 208523 in reply to 208514

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

    Hi

     

    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,   


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  11-18-2009, 4:39 AM 208530 in reply to 208523

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

    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.

     
  •  11-18-2009, 5:08 AM 208542 in reply to 208523

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

    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?

     
  •  11-18-2009, 6:06 AM 208559 in reply to 208542

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

    Hi

     

    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,


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML