DocumentLastSection Property

Gets the last section in the document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public Section LastSection { get; }

Property Value

Type: Section


Returns null if there are no sections.


Shows how to edit the last section of a document.
// Open the template document, containing obsolete copyright information in the footer
Document doc = new Document(MyDir + "Footer.docx");

// Create a new copyright information string to replace an older one with
int currentYear = DateTime.Now.Year;
string newCopyrightInformation = $"Copyright (C) {currentYear} by Aspose Pty Ltd.";

FindReplaceOptions findReplaceOptions = new FindReplaceOptions();
findReplaceOptions.MatchCase = false;
findReplaceOptions.FindWholeWordsOnly = false;

// Each section has its own set of headers/footers,
// so the text in each one has to be replaced individually if we want the entire document to be affected
HeaderFooter firstSectionFooter = doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary];
firstSectionFooter.Range.Replace("(C) 2006 Aspose Pty Ltd.", newCopyrightInformation, findReplaceOptions);

HeaderFooter lastSectionFooter = doc.LastSection.HeadersFooters[HeaderFooterType.FooterPrimary];
lastSectionFooter.Range.Replace("(C) 2006 Aspose Pty Ltd.", newCopyrightInformation, findReplaceOptions);

doc.Save(ArtifactsDir + "Document.Sections.docx");

See Also