SectionBody Property

Returns the Body child node of the section.

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

ExpandedSyntax

public Body Body { get; }

Property Value

Type: Body

ExpandedRemarks

Body contains main text of the section.

Returns null if the section does not have a Body node among its children.

ExpandedExamples

Clears main text from all sections from the document leaving the sections themselves.
// Open a document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Section 1");
builder.InsertBreak(BreakType.SectionBreakNewPage);
builder.Write("Section 2");

// This shows what is in the document originally
// The document has two sections
Assert.AreEqual($"Section 1{ControlChar.SectionBreak}Section 2{ControlChar.SectionBreak}", doc.GetText());

// Loop through all sections in the document
foreach (Section section in doc.Sections.OfType<Section>())
{
    // Each section has a Body node that contains main story (main text) of the section
    Body body = section.Body;

    // This clears all nodes from the body
    body.RemoveAllChildren();

    // Technically speaking, for the main story of a section to be valid, it needs to have
    // at least one empty paragraph. That's what the EnsureMinimum method does
    body.EnsureMinimum();
}

// Check how the content of the document looks now
Assert.AreEqual($"{ControlChar.SectionBreak}{ControlChar.SectionBreak}", doc.GetText());

ExpandedSee Also