Write text to footer in each section

I need to write some text to the footer in each section of a document. The text may not be the same in each section so I cannot use the LinkToPrevious setting. Essentially what I want is

Dim DocSections As SectionCollection = docOutput.Sections
Dim HeaderOrFooter As HeaderFooter
For Each thisSection As Section In DocSections
   HeaderOrFooter = thisSection.HeadersFooters(HeaderFooterType.FooterPrimary)

   ` write to the section text
Next thisSection

I cannot see how to write to the section. I have seen code that does

builder.MoveToHeaderFooter(typHeaderFooterType)
builder.Write("SomeText")

but this only seems to work on the first section.

what am I missing??

Thanks

john

Hi John,

Thanks for your inquiry. Please use following code example to achieve your requirements. Use HeaderFooterCollection.LinkToPrevious method to link or unlinks all headers and footers to the corresponding headers and footers in the previous section. Hope this helps you.

Dim doc As New Document(MyDir + "in.docx")
Dim builder As New DocumentBuilder(doc)
For i As Integer = 0 To doc.Sections.Count - 1
    builder.MoveToSection(i)
    builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary)
    builder.Writeln("Footer contents ")
    doc.Sections(i).HeadersFooters.LinkToPrevious(False)
Next
doc.Save(MyDir + "Out.docx")

If you still face problem, please share your input Word document here for testing purposes. We will then provide you more information about your query along with code.

Thanks for that code - it was very helpful.

Is there a property that can tell me if the LinkToPrevious setting for a Section is True or False. If LinkToPrevious is False I need to add some text to the Footer but if LinkToPrevious is True I don’t need to do anything as it can inherit the Footer from the previous section

john

Hi John,

Thanks for your inquiry. Please use HeaderFooter.IsLinkedToPrevious property to check either a header or footer is linked to the corresponding header or footer in the previous section or not.

Please let us know if you have any more queries.