Doc revisions aspose word

Hi all,

I want to know how paragraphe or how section exactly revised on a word document.
is it possible ?

the code HasRevisions work on doc but not on paragraphe.

Best regards,
Jugurtha

@Jugurtha_MAHDAD Please consider the following code.

private bool HasRevisions(Node para)
{
    Document doc = (Document)para.Document;
    foreach (Revision revision in doc.Revisions)
    {
        Node node = revision.ParentNode;
        while (node != null)
        {
            if (para == node)
                return true;
            node = node.ParentNode;
        }
    }
    return false;
}

Usage:

Assert.AreEqual(true, HasRevisions(doc.Sections[1]));
Assert.AreEqual(false, HasRevisions(doc.FirstSection.Body.Paragraphs[1]));

Hi Vadim,

Thank you for your response.
I have the same Node but your code if (para == node) is not working.

Have you any “compare” function to compre two nodes ?

Best regards,

@Jugurtha_MAHDAD Please attach a sample document in which this happens and indicate which paragraph with the revision is not displayed.

MPA V6 - Volume 4 v6.2.1 MASTER_clean (1) (2).docx (3.5 MB)

the revision is on this paragraph:
4 ANNEXE 4 : DICTIONNAIRE DES MESSAGES

Can you please delete the file after you download it ?

@Jugurtha_MAHDAD Don’t worry, it’s safe. Your attachments can only be uploaded by you and Aspose employees. We will check it and provide you with additional information.

@Jugurtha_MAHDAD As far as I can see, this paragraph does not contain revisions. The code I posted above returns “false”.
screen.png (28.1 KB)

MPA V6 - Volume 4 v6.2.1 MASTER_clean (1) (2) (1).docx (3.5 MB)

i just add insertion

on the last file i have a delete revision
image.png (29.1 KB)

@Jugurtha_MAHDAD The paragraph containing “4 ANNEXE 4 : DICTIONNAIRE DES MESSAGES” still does not have revisions. There are revisions in the next one, which is shown by the code above.

This is my revision on this paragraphe, it’s on my picture
image.png (14.7 KB)

MPA V6 - Volume 4 v6.2.1 MASTER_clean (1) (2) (1).docx (3.5 MB)

@Jugurtha_MAHDAD
Please, look at the attached screenshot. There I numerated part of the paragraphs of your document. There are no revisions in the first, third and fourth paragraphs. Revisions are present only in the second of those numerated. The code above produces exactly this result. Once again, there are no revisions in the first paragraph containing the text “4 ANNEXE 4 : DICTIONNAIRE DES MESSAGES”.
screen2.png (98.8 KB)

For me i want to know if i have any revision on one or many paragraphes of all the title 4 (4.1, 4.2) if it’s ok i return true, else i return false.

@Jugurtha_MAHDAD Please consider the following code.

Document doc = new Document("MPA V6 - Volume 4 v6.2.1 MASTER_clean (1) (2) (1).docx");
doc.UpdateListLabels();
string label = string.Empty;
string paraText = string.Empty;
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (para.ParagraphStyle.IsHeading)
    {
        label = para.ListLabel.LabelString;
        paraText = para.GetText().Trim();
    }

    if (HasRevisions(para) && label.Length > 0)
    {
        Console.WriteLine(label + " " + paraText);
        label = string.Empty;
        paraText = string.Empty;
    }
}

Hi Vadim,

Have you any response about this topic ?

Best regards,

@Jugurtha_MAHDAD If you simply need to check whether paragraph has any revisions or not, you can try using code like the following:

private static bool HasAnyRevision(Paragraph p)
{
    // Check if paragraph itself has any revisions.
    if (p.IsDeleteRevision || p.IsInsertRevision || p.IsFormatRevision || p.IsMoveFromRevision || p.IsMoveToRevision)
        return true;

    // Check childnodes whether they have any revisions.
    foreach (Node child in p.ChildNodes)
    {
        Inline inline = child as Inline;
        if (inline != null)
        {
            if (inline.IsDeleteRevision || inline.IsInsertRevision || inline.IsFormatRevision ||
                inline.IsMoveFromRevision || inline.IsMoveToRevision)
                return true;
        }
    }

    return false;
}