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.11
public void UpdateWordCount(
	bool updateLinesCount


Type: SystemBoolean
True if number of lines in the document shall be calculated.
This method will rebuild page layout of the document.
Shows how to keep track of the word count.
// 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

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

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