BuiltInDocumentPropertiesLines Property

Represents an estimate of the number of lines in the document.

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


public int Lines { get; set; }

Property Value

Type: Int32


Aspose.Words updates this property when you call UpdateWordCount(Boolean).


Shows how to update all list labels in a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
                "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
builder.Write("Ut enim ad minim veniam, " +
                "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.");

// Aspose.Words does not track document metrics like these in real time.
Assert.AreEqual(0, doc.BuiltInDocumentProperties.Characters);
Assert.AreEqual(0, doc.BuiltInDocumentProperties.Words);
Assert.AreEqual(1, doc.BuiltInDocumentProperties.Paragraphs);
Assert.AreEqual(1, doc.BuiltInDocumentProperties.Lines);

// To get accurate values for three of these properties, we will need to update them manually.

Assert.AreEqual(196, doc.BuiltInDocumentProperties.Characters);
Assert.AreEqual(36, doc.BuiltInDocumentProperties.Words);
Assert.AreEqual(2, doc.BuiltInDocumentProperties.Paragraphs);

// For the line count, we will need to call a specific overload of the updating method.
Assert.AreEqual(1, doc.BuiltInDocumentProperties.Lines);


Assert.AreEqual(4, doc.BuiltInDocumentProperties.Lines);
Shows how to work with document properties in the "Content" category.
public void Content()
    // Open a document with a couple paragraphs of content
    Document doc = new Document(MyDir + "Paragraphs.docx");

    // The properties we will work with are members of the BuiltInDocumentProperties attribute
    BuiltInDocumentProperties properties = doc.BuiltInDocumentProperties;

    // By using built in properties,
    // we can treat document statistics such as word/page/character counts as metadata that can be glanced at without opening the document
    // These properties are accessed by right-clicking the file in Windows Explorer and navigating to Properties > Details > Content
    // If we want to display this data inside the document, we can use fields such as NUMPAGES, NUMWORDS, NUMCHARS etc.
    // Also, these values can also be viewed in Microsoft Word by navigating File > Properties > Advanced Properties > Statistics
    // Page count: The PageCount attribute shows the page count in real time and its value can be assigned to the Pages property
    properties.Pages = doc.PageCount;
    Assert.AreEqual(6, properties.Pages);

    // Word count: The UpdateWordCount() automatically assigns the real time word/character counts to the respective built in properties
    Assert.AreEqual(1035, properties.Words);
    Assert.AreEqual(6026, properties.Characters);
    Assert.AreEqual(7041, properties.CharactersWithSpaces);

    // Line count: Count the lines in a document and assign value to the Lines property
    LineCounter lineCounter = new LineCounter(doc);
    properties.Lines = lineCounter.GetLineCount();
    Assert.AreEqual(142, properties.Lines);

    // Paragraph count: Assign the size of the count of child Paragraph-nodes to the Paragraphs built in property
    properties.Paragraphs = doc.GetChildNodes(NodeType.Paragraph, true).Count;
    Assert.AreEqual(29, properties.Paragraphs);

    // Check the real file size of our document
    Assert.AreEqual(20310, properties.Bytes);

    // Template: The Template attribute can reflect the filename of the attached template document
    doc.AttachedTemplate = MyDir + "Business brochure.dotx";
    Assert.AreEqual("Normal", properties.Template);          
    properties.Template = doc.AttachedTemplate;

    // Content status: This is a descriptive field
    properties.ContentStatus = "Draft";

    // Content type: Upon saving, any value we assign to this field will be overwritten by the MIME type of the output save format
    Assert.AreEqual(string.Empty, properties.ContentType);

    // If the document contains links and they are all up to date, we can set this to true

    doc.Save(ArtifactsDir + "Properties.Content.docx");

/// <summary>
/// Util class that counts the lines in a document.
/// Upon construction, traverses the document's layout entities tree,
/// counting entities of the "Line" type that also contain real text.
/// </summary>
private class LineCounter
    public LineCounter(Document doc)
        mLayoutEnumerator = new LayoutEnumerator(doc);


    public int GetLineCount()
        return mLineCount;

    private void CountLines()
            if (mLayoutEnumerator.Type == LayoutEntityType.Line)
                mScanningLineForRealText = true;

            if (mLayoutEnumerator.MoveFirstChild())
                if (mScanningLineForRealText && mLayoutEnumerator.Kind.StartsWith("TEXT"))
                    mScanningLineForRealText = false;
        } while (mLayoutEnumerator.MoveNext());

    private readonly LayoutEnumerator mLayoutEnumerator;
    private int mLineCount;
    private bool mScanningLineForRealText;

ExpandedSee Also