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

Free Support Forum - aspose.com

Inserting Field Programatically

Hi I'm trying to avoid using the DocumentBuilder to add the Page Number to a Word Document Footer. Here is the sample code:

Dim footer As HeaderFooter = New HeaderFooter(m_doc, HeaderFooterType.FooterPrimary)
section.HeadersFooters.Add(footer)

Dim fpara As Paragraph = New Paragraph(m_doc)
footer.Paragraphs.Add(fpara)

Dim frun As Run = New Run(m_doc, "TEST FOOTER - ")
fpara.Runs.Add(frun)

'I want to insert this field programatically
builder.MoveTo(fpara)
builder.InsertField("PAGE", "")

Dim frun2 As Run = New Run(m_doc, " -")
fpara.Runs.Add(frun2)

How can I avoid using the builder to add the PAGE to the word document?

Thanks

Hi

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

Thanks for your inquiry. There is no way to insert field without using DocumentBuilder. May I know why you need to avoid using DocumentBuilder?

Best regards,

It's a bit complicated but the jist of it is that an XML definition is parsed and based on what is read the document is generated (like a report generator, where the XML describes the report and data is being retreived while the XML is parsed). So all the object are held as references so that imbeded objects (in the XML definition) know what parents it references and it can access them to retrive data bits and the like. I would compare it to "assembling" a document as oppose to "writing" a document in a more serialized type of way.

But if there is no other way I'll try to make it work!