Revision Class

Represents a revision (tracked change) in a document node or style. Use RevisionType to check the type of this revision.
Inheritance Hierarchy

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.2
public class Revision

The Revision type exposes the following members.

Public propertyCode exampleAuthor
Gets or sets the author of this revision. Can not be empty string or null.
Public propertyCode exampleDateTime
Gets or sets the date/time of this revision.
Public propertyCode exampleGroup
Gets the revision group. Returns null if the revision does not belong to any group.
Public propertyCode exampleParentNode
Gets the immediate parent node (owner) of this revision. This property will work for any revision type other than StyleDefinitionChange.
Public propertyCode exampleParentStyle
Gets the immediate parent style (owner) of this revision. This property will work for only for the StyleDefinitionChange revision type.
Public propertyCode exampleRevisionType
Gets the type of this revision.
Public methodCode exampleAccept
Accepts this revision.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodCode exampleReject
Reject this revision.
Public methodToString (Inherited from Object.)
Shows how to check if a document has revisions.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

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

// In order for our edits to count as revisions, we need to declare an author and start tracking them
doc.StartTrackRevisions("John Doe", DateTime.Now);
builder.Write("This is revision #1. ");

// This flag corresponds to the "Track Changes" option being turned on in Microsoft Word, to track the editing manually
// done there and not the programmatic changes we are about to do here

// As well as nodes in the document, revisions get referenced in this collection
Assert.AreEqual(1, doc.Revisions.Count);

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);

// Deleting content also counts as a revision
// The most recent revisions are put at the start of the 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 deletion revision will assimilate it into the paragraph text and remove it from the collection
Assert.AreEqual(1, doc.Revisions.Count);

// Once the delete revision is accepted, the nodes that it concerns are removed and their text will not show up here
Assert.AreEqual("This is revision #1.", doc.GetText().Trim());

// The second insertion 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());

// This takes us back to not counting changes as revisions

builder.Writeln("This also does not count as a revision.");
Assert.AreEqual(0, doc.Revisions.Count);

doc.Save(ArtifactsDir + "Revisions.docx");
See Also