Aspose word c# revisions

Hi all,

I want to extract all the revisions of a word doc, and when i execute this code:
foreach (Revision revision in doc.Revisions){…}

I have many duplicate revision like the screenshot below:
image.png (10.8 KB)

And also i don’t want to take the revision of the header if it’s possible.

Have you any solution for this ?

Best regards,
Jugurtha

@Jugurtha_MAHDAD Could you please attach your problematic document here for testing? We will check the issue and provide you more information.

The file below:
Source revision.zip (2.6 MB)

can you delete it please after download ?

Best regards,
Jugurtha

@Jugurtha_MAHDAD A revision in Aspose.Words is a change in one document node. A set of sequential revisions of the same type in adjacent document nodes forms a revision group. Similar revision groups are displayed in the “Reviewing Pane” of MS Word. You can get the revision group by using Document.Revisions.Groups property and all revision of document using Document.Revisions property. Also you can get the group associated with particular revision with Revision.Group property.

So if you want to get the result similar to the “Reviewing Pane” of MS Word you should iterate through Document.Revisions.Groups instead of Document.Revisions.

To identify whether the Revision is in the header you could check the Revision.ParentNode ancestors with the code like this:

revision.ParentNode?.GetAncestor(NodeType.HeaderFooter) != null

Thank you Konstantin,

But the revision group don’t contain ParentNode, how i can found if it’s on the header or no, and how i can found the label string of the revision like in the code below ?
label = para1.ListLabel.LabelString;
paraText = para1.GetText().Trim();

and i want also find the dateTime of the revision.

best regards,
Jugurtha

@Jugurtha_MAHDAD

But the revision group don’t contain ParentNode, how i can found if it’s on the header or no

One of the options to do this is to check whether the group contains the revisions in the header. Here is code example:

var groupRevisions = doc.Revisions.Where(revision => revision.Group == group);
bool isHeaderGroup = groupRevisions.Any(revision => revision.ParentNode?.GetAncestor(NodeType.HeaderFooter) != null);

how i can found the label string of the revision like in the code below ?

I’m not quite understand what data you want to get for a revision group. But if you are able to get the desired result for a particular revision then for a revision group you should iterate though the related revisions and collect the required data.

and i want also find the dateTime of the revision.

As the revision group may contains several revisions, there are no single date related to the group. If you need a single date, you could use the date of the first revision in the group. Here is code example:

var groupRevisions = doc.Revisions.Where(revision => revision.Group == group);
DateTime date = groupRevisions.First().DateTime;