BodyEnsureMinimum Method

If the last child is not a paragraph, creates and appends one empty paragraph.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public void EnsureMinimum()
Examples
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
Console.WriteLine(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
Console.WriteLine(doc.GetText());
See Also