Document.LastSection property

Gets the last section in the document.

public Section LastSection { get; }


Returns null if there are no sections.


Shows how to create a new section with a document builder.

Document doc = new Document();

// A blank document contains one section by default,
// which contains child nodes that we can edit.
Assert.AreEqual(1, doc.Sections.Count);

// Use a document builder to add text to the first section.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");

// Create a second section by inserting a section break.

Assert.AreEqual(2, doc.Sections.Count);

// Each section has its own page setup settings.
// We can split the text in the second section into two columns.
// This will not affect the text in the first section.
builder.Writeln("Column 1.");
builder.Writeln("Column 2.");

Assert.AreEqual(1, doc.FirstSection.PageSetup.TextColumns.Count);
Assert.AreEqual(2, doc.LastSection.PageSetup.TextColumns.Count);

doc.Save(ArtifactsDir + "Section.Create.docx");

See Also