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

Free Support Forum - aspose.com

Reading bookmarks from a Table.Range object deleted the bookmarks

BookMarkBug.zip (12.6 KB)
I have an issue with the code below. I want to know if a table has a bookmark and for this I identify the table and access table.Range.Bookmarks. If I access this the bookmark gets deleted from the document.
Is this a bug?

            var fileName = Path.Combine(Directory.GetCurrentDirectory(), "BookmarkBug.docx");
            
            var lic = new License();
            lic.SetLicense("########");
            var document = new Document(fileName);
            Assert.IsTrue(document.Range.Bookmarks.Count == 5);

            var allTables = document.GetChildNodes(NodeType.Table, true);

            var bookmarks = allTables[0].Range.Bookmarks;
            Assert.IsTrue(document.Range.Bookmarks.Count == 5);

I didn’t found an upload option otherwise I would add you an example word file.

@JochenBernhardt,

Please ZIP and upload your input Word document here for testing (see this upload-button.zip (9.7 KB)). We will investigate the issue on our end and provide you more information.

thanks for the hint. I uploaded the file.

@JochenBernhardt,

While using the latest version of Aspose.Words i.e. 18.2, we managed to reproduce this issue on our end. We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-16458. Your thread has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

The issues you have found earlier (filed as WORDSNET-16458) have been fixed in this Aspose.Words for .NET 18.3 update and this Aspose.Words for Java 18.3 update.

Hi,

I’m a colleague of Jochen and tested the new version 18.3. The reported problem has been solved, but a probably related issue is still not fixed. When trying to access the bookmarks by looping over the tables, they are not part of the BookmarkCollection.

You can reproduce the issue with the file from Jochen and the following console application:

    public static void GetBookmarkOfTable()
    {
        var doc = new Document("C:\\Users\\st004186\\Downloads\\BookMarkBug\\BookMarkBug.docx");

        Console.WriteLine("Count before accessing child node: " + doc.Range.Bookmarks.Count);

        var tables = doc.GetChildNodes(NodeType.Table, true);

        Console.WriteLine();
        Console.WriteLine("###BOOKMARKS###");

        foreach (Table table in tables)
        {
            var bookmarks = table.Range.Bookmarks;
            foreach (Bookmark bookmark in bookmarks)
            {
                Console.WriteLine(bookmark.Name);
            }
        }

        Console.WriteLine();
        Console.WriteLine("Count after accessing child node: " + doc.Range.Bookmarks.Count);
        Console.ReadLine();
    }

This is the output for the different versions:

Version 16.8 (Expected behaviour)

Count before accessing child node: 5

###BOOKMARKS###
TableA
_GoBack
_Ref372039174
TableB
_Ref372039207

Count after accessing child node: 5

Version 18.2 (Before the bug fix)

Count before accessing child node: 5

###BOOKMARKS###
_GoBack
_Ref372039174
_Ref372039207

Count after accessing child node: 3

Version 18.3 (After the bug fix)

Count before accessing child node: 5

###BOOKMARKS###
_GoBack
_Ref372039174
_Ref372039207

Count after accessing child node: 5

Thanks for looking into this!

Best regards
Stephan

@Djeramon,

Thanks for the details. We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-16637. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

Hello,

has there been any progress on this issue? Can we expect a fix any time soon?

Thanks and best regards
Stephan

@Djeramon,

Unfortunately, your issue (WORDSNET-16637) is not resolved yet. We will inform you via this thread as soon as this issue is resolved. We apologize for any inconvenience. Please see the following analysis details.

The document contains five bookmarks. The bookmarks with names ‘TableA’ and ‘TableB’ have their BookmarkEnds at the table level. Aspose.Words currently does not support such kind of bookmarks, so these BookmarkEnds are treated as if they reside just after corresponded tables. Therefore, these two bookmarks are not in tables ranges, as only their BookmarkStarts reside inside tables at the paragraph level.

This is a limitation of our current model i.e. Aspose.Words does not support bookmarks at the table level.

However, we should change such behavior to be closer to MS Word after bookmarks at the table level are supported as per WORDSNET-721.

The issues you have found earlier (filed as WORDSNET-16637) have been fixed in this Aspose.Words for .NET 18.9 update and this Aspose.Words for Java 18.9 update.