Numbering each page

Hi I want to number each page i print. But the pages can have children pages as well. Please find below my code.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim myPage As New CMSPage(CInt(Request("Pageid")))

Dim myDoc As New Aspose.Words.Document()

Dim builder As New DocumentBuilder(myDoc)

PrintChildPages(myPage, myDoc, builder)

myDoc.Save(myPage.Name.ToString & ".doc", SaveFormat.Doc, SaveType.OpenInWord, Response)

End Sub

Private Sub PrintChildPages(ByVal page As CMSPage, ByVal mydoc As Aspose.Words.Document, ByVal builder As DocumentBuilder)

AsposeHelper.Cells.SetLicense()

builder.StartTable()

builder.RowFormat.Height = 100

Dim layoutXml As XmlDocument = bwAE.Xml.parse(page.Layout.Structure)

For Each node As XmlNode In layoutXml.SelectNodes("/root/row")

For Each el As XmlNode In node.SelectNodes("content")

builder.InsertCell()

Dim cellformat As Aspose.Words.Tables.CellFormat = builder.CellFormat

cellformat.Width = 510

cellformat.LeftPadding = 30

cellformat.RightPadding = 30

cellformat.TopPadding = 30

Dim sectionID As Integer = bwAE.Xml.intAttribute(el, "id")

If Not String.IsNullOrEmpty(page.Content(sectionID).Content.ToString) Then

builder.InsertHtml(page.Content(sectionID).Content)

End If

builder.EndRow()

Next

Next

builder.EndTable()

If page.Children.Count > 0 Then

For Each childpage As CMSPage In page.Children

PrintChildPages(childpage, mydoc, builder)

Next

End If

End Sub

Could you please suggest how to add page number like 1 for parent and 1.1 and 1.2 for its child and further 1.1.1 and 1.1.2 for its children…

Thanks for your reply in advance

Hi
Thanks for your request. I think you can use List in this case. See the following link for more information.
https://docs.aspose.com/words/net/working-with-lists/
You can try using code like the following:

Sub Main()
Dim myDoc As New Aspose.Words.Document()
Dim builder As New DocumentBuilder(myDoc)
'Create list
Dim myList As Aspose.Words.Lists.List = myDoc.Lists.Add(Lists.ListTemplate.OutlineLegal)
'Read XML document (this is dummy data)
Dim xmlDoc As System.Xml.XmlDocument = New System.Xml.XmlDocument()
xmlDoc.Load("C:\Temp\test.xml")
PrintChildPages(CType(xmlDoc.DocumentElement, System.Xml.XmlNode), builder, 0, myList)
myDoc.Save("C:\Temp\out.doc")
End Sub
Private Sub PrintChildPages(ByVal xmlNode As System.Xml.XmlNode, ByVal builder As DocumentBuilder, ByVal level As Integer, ByVal list As Aspose.Words.Lists.List)
builder.ListFormat.List = list
builder.ListFormat.ListLevelNumber = level
builder.Writeln("item")
builder.ListFormat.RemoveNumbers()
builder.StartTable()
builder.RowFormat.Height = 100
builder.InsertCell()
Dim cellformat As Aspose.Words.Tables.CellFormat = builder.CellFormat
cellformat.Width = 510
cellformat.LeftPadding = 30
cellformat.RightPadding = 30
cellformat.TopPadding = 30
builder.Write(xmlNode.Attributes("value").Value)
builder.EndRow()
builder.EndTable()
If xmlNode.ChildNodes.Count > 0 Then
For Each node As System.Xml.XmlNode In xmlNode.ChildNodes
PrintChildPages(node, builder, level + 1, list)
Next
End If
End Sub

Here is XML that I used as dummy data:

<?xml version="1.0" encoding="utf-8"?>
<root value="root element">
	<row value="this is item 1.1">
		<row value="this is item 1.1.1">
			<row value="this is item 1.1.1.1" />
		</row>
		<row value="this is item 1.1.2" />
	</row>
	<row value="this is item 1.2">
		<row value="this is item 1.2.1">
			<row value="this is item 1.2.1.1" />
		</row>
	</row>
	<row value="this is item 1.3">
	</row>
</root>

Hope this helps.
Best regards.