DocumentUpdateWordCount Method (Boolean)
Updates word count properties of the document, optionally updates Lines property.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
Syntax
public void UpdateWordCount(
	bool updateLinesCount
)

Parameters

updateLinesCount
Type: SystemBoolean
True if number of lines in the document shall be calculated.
Remarks
This method will rebuild page layout of the document.
Examples
Shows how to keep track of the word count.
[C#]

// Create an empty document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("This is the first line.");
builder.Writeln("This is the second line.");
builder.Writeln("These three lines contain eighteen words in total.");

// The fields that keep track of how many lines and words a document has are not automatically updated
// An empty document has one paragraph by default, which contains one empty line
Assert.AreEqual(0, doc.BuiltInDocumentProperties.Words);
Assert.AreEqual(1, doc.BuiltInDocumentProperties.Lines);

// To update them we have to use this method
// The default constructor updates just the word count
doc.UpdateWordCount();

Assert.AreEqual(18, doc.BuiltInDocumentProperties.Words);
Assert.AreEqual(1, doc.BuiltInDocumentProperties.Lines);

// If we want to update the line count as well, we have to use this overload
doc.UpdateWordCount(true);

Assert.AreEqual(18, doc.BuiltInDocumentProperties.Words);
Assert.AreEqual(3, doc.BuiltInDocumentProperties.Lines);
See Also