Adding a footer to an appended document

Hi,
I’m trying to add some footer text to an appended document but am having no success. Here is the function I’m using. Can you please tell me why this is not working?
Thanks

public void AddDocument(string DocumentNameandPath, string FooterText)
{
    if (String.IsNullOrEmpty(DocumentNameandPath))
        throw new ArgumentException("DocumentNameandPath is null or empty.", "DocumentNameandPath");
    // Open the source document.
    Document srcDoc = new Document(DocumentNameandPath);
    if (FooterText.Length > 0)
    {
        foreach (Section srcSection in srcDoc)
        {
            HeaderFooter Footer = srcSection.HeadersFooters[HeaderFooterType.FooterPrimary];
            if (Footer == null)
            {
                Footer = new HeaderFooter(srcSection.Document, HeaderFooterType.FooterPrimary);
                srcSection.HeadersFooters.Add(Footer);
            }
        }
        srcDoc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].Range.Replace("*", FooterText, false, false);
    }
    mDocument.Document.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
    // AppendDoc(mDocument, srcDoc, FooterText);
}

Hi
Thanks for your request. Please try using the following code:

public static void AddDocument(string DocumentNameandPath, string FooterText)
{
    if (String.IsNullOrEmpty(DocumentNameandPath))
        throw new ArgumentException("DocumentNameandPath is null or empty.", "DocumentNameandPath");
    // Open the source document.
    Document srcDoc = new Document(DocumentNameandPath);
    DocumentBuilder builder = new DocumentBuilder(srcDoc);
    if (FooterText.Length > 0)
    {
        for (int sectIdx = 0; sectIdx < srcDoc.Sections.Count; sectIdx++)
        {
            // move documentbuilder cursor to the current section
            builder.MoveToSection(sectIdx);
            // move documentbuilder cursor to the footer
            builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
            // Insert text into teh footer
            builder.Write(FooterText);
        }
    }
    mDocument.Document.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles);
}

Also see teh following link to learn how to insert header/footer into the document:
https://docs.aspose.com/words/net/working-with-headers-and-footers/
Best regards.