Apply numbered list to paragraphs within Bookmark

Hello,

i have a document containing various bookmarks.
I need to move to a specific bookmark and applay numbered list format to all paragraphs within the bookmark.
How can i obtain this?

I’m using Aspose.Words .NET…tried the following code:

            Dim bm As Bookmark = document_.Range.Bookmarks(bookmark_)
            If Not bm Is Nothing Then
                Dim currentNode As Node = bm.BookmarkStart
                While (Not currentNode Is Nothing AndAlso Not currentNode.Equals(bm.BookmarkEnd))
                    If currentNode.NodeType = NodeType.Run Then
                        DirectCast(currentNode, Run).ParentParagraph.ListFormat.ApplyNumberDefault()
                    End If
                    currentNode = currentNode.NextSibling
                End While
            Else
                bLg.Error("bookmark " & bookmark_ & "not found")
            End If

But this way only the first paragraph is numbered.
Can you help?

Thanks in advance.

Test.zip (7.8 KB)

@g.erdl.ots-ag.de

Please use the following code example to get the desired output.

Dim doc = New Document(MyDir & "test.doc")
Dim bookmark As Bookmark = doc.Range.Bookmarks("T01_Nummerierung")
Dim list As List = doc.Lists.Add(ListTemplate.NumberDefault)
Dim node As Node = CType(bookmark.BookmarkStart, Node)
(CType(node.ParentNode, Paragraph)).ListFormat.List = list

While node <> bookmark.BookmarkEnd
node = node.NextPreOrder(doc)

If node.NodeType = NodeType.Paragraph Then
(CType(node, Paragraph)).ListFormat.List = list
End If
End While

doc.Save(MyDir & "output.docx")

This works perfectly for me…thanks

@g.erdl.ots-ag.de

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.