How to add text to header and footer using C#

The following code prepends the footer on the first section of a doc. However the footer on section 2 just gets overwritten.

How can I prepend the footer to every section?

private void InsertFooterWatermark(Aspose.Words.Document doc, string text, string statusName, string userName, string timezoneId)
    {
        bool footerInserted = false;

        foreach (Section section in doc)
        {
            if (section.HeadersFooters.Count == 0)
            {
                DocumentBuilder builder = new DocumentBuilder(doc);
                builder.MoveToSection(doc.Sections.IndexOf(section));
                builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
                footerInserted = InsertFooterText(text, statusName, userName, builder);
            }
            else
            {
                foreach (HeaderFooter footer in section.HeadersFooters)
                {
                    if (IsFooter(footer))
                    {
                        DocumentBuilder builder = new DocumentBuilder(doc);
                        builder.MoveToSection(doc.Sections.IndexOf(section));
                        builder.MoveToHeaderFooter(footer.HeaderFooterType);
                        footerInserted = InsertFooterText(text, statusName, userName, builder);
                    }
                }
                if (!footerInserted)
                {
                    DocumentBuilder builder = new DocumentBuilder(doc);
                    builder.MoveToSection(doc.Sections.IndexOf(section));
                    builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
                    footerInserted = InsertFooterText(text, statusName, userName, builder);
                }
            }
        }
    }

It calls this method:

private static bool InsertFooterText(string text, string statusName, string userName, DocumentBuilder builder)
    {
        builder.Font.Name = "Tahoma";
        builder.Font.Size = 7;
        builder.Font.Bold = true;
        builder.Write($"[{text} | {userName} | {statusName}] ");
        builder.Font.Bold = false;
        return true;
    }

I have attached a simple doc. It prepends the first footer but not the second. Link to previous doesn’t help either. word with footer and 2 sections.zip (14.0 KB)

@RCAtWork

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.