Revision Class

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

ExpandedInheritance Hierarchy

SystemObject
  Aspose.WordsRevision

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

ExpandedSyntax

public class Revision

The Revision type exposes the following members.

ExpandedProperties

  NameDescription
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.

ExpandedMethods

  NameDescription
Public methodCode exampleAccept
Accepts this revision.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodCode exampleReject
Reject this revision.
Public methodToString (Inherited from Object.)

ExpandedExamples

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

Assert.IsFalse(doc.HasRevisions);

// 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.IsTrue(doc.HasRevisions);
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.
Assert.IsFalse(doc.TrackRevisions);

// 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.
doc.FirstSection.Body.FirstParagraph.Runs[0].Remove();

// 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.
doc.Revisions[0].Accept();

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.
doc.Revisions[0].Reject();

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

ExpandedSee Also