DocumentTrackRevisions Property

True if changes are tracked when this document is edited in Microsoft Word.

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


public bool TrackRevisions { get; set; }

Property Value

Type: Boolean


Setting this option only instructs Microsoft Word whether the track changes is turned on or off. This property has no effect on changes to the document that you make programmatically via Aspose.Words.

If you want to automatically track changes as they are made programmatically by Aspose.Words to this document use the StartTrackRevisions(String, DateTime) method.


Shows how to work with revisions in a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Standard editing of the document does not count as a revision.
builder.Write("This does not count as a revision. ");


// To register our edits as revisions, we need to declare an author, and then start tracking them.
doc.StartTrackRevisions("John Doe", DateTime.Now);

builder.Write("This is revision #1. ");

Assert.AreEqual(1, doc.Revisions.Count);

// This flag corresponds to the Review -> Tracking -> "Track Changes" option is turned on in Microsoft Word, 
// and it is independent of the programmatic revision tracking that is taking place here.

// Our first revision is an insertion-type revision since we added text with the document builder.
Revision revision = doc.Revisions[0];
Assert.AreEqual("John Doe", revision.Author);
Assert.AreEqual("This is revision #1. ", revision.ParentNode.GetText());
Assert.AreEqual(RevisionType.Insertion, revision.RevisionType);
Assert.AreEqual(revision.DateTime.Date, DateTime.Now.Date);
Assert.AreEqual(doc.Revisions.Groups[0], revision.Group);

// Remove a run to create a deletion-type revision.

// Adding a new revision places it at the beginning of the revision collection.
Assert.AreEqual(RevisionType.Deletion, doc.Revisions[0].RevisionType);
Assert.AreEqual(2, doc.Revisions.Count);

// Insert revisions are treated as document text by the GetText() method before they are accepted
// since they are still nodes with text and are in the body.
Assert.AreEqual("This does not count as a revision. This is revision #1.", doc.GetText().Trim());

// Accepting the delete revision will remove its parent node from the paragraph text,
// and then remove the revision itself from the collection.

Assert.AreEqual(1, doc.Revisions.Count);

// Accepting a delete revision removes all the nodes that it concerns,
// so their contents will no longer be anywhere in the document.
Assert.AreEqual("This is revision #1.", doc.GetText().Trim());

// The insertion-type revision is now at index 0, which we can reject to ignore and discard it.

Assert.AreEqual(0, doc.Revisions.Count);
Assert.AreEqual("", doc.GetText().Trim());

See Also