DocumentLastSection Property
Gets the last section in the document.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 20.1
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 + "HeaderFooter.ReplaceText.doc");

// We have a document with 2 sections, this way FirstSection and LastSection are not the same
Assert.AreEqual(2, doc.Sections.Count);

string newCopyrightInformation = string.Format("Copyright (C) {0} by Aspose Pty Ltd.", DateTime.Now.Year);
FindReplaceOptions findReplaceOptions =
    new FindReplaceOptions { MatchCase = false, FindWholeWordsOnly = false };

// Access the first and the last sections
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);

// Sections are also accessible via an array
Assert.AreEqual(doc.FirstSection, doc.Sections[0]);
Assert.AreEqual(doc.LastSection, doc.Sections[1]);

doc.Save(ArtifactsDir + "HeaderFooter.ReplaceText.doc");
See Also