Get Original or Revised (Final) Version of Paragraphs Text in Word Document using C# .NET

Is there a direct way to access Original and Final versions of a document.
Though I apply “Original” or “Final” and parse paragraphs I am receiving same result

doc.RevisionsView = RevisionsView.Final;
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    Console.WriteLine(para.Range.Text);
}

raj track.zip (9.8 KB)

@crshekharam,

Please elaborate your inquiry further by providing complete details of your use-case. You can also provide screenshots which will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.

What do you mean by “Original and Final versions of a document”? Can you achieve this by using MS Word desktop application? What text do you expect Aspose.Words to return for both cases?

Thanks for your cooperation.

This is in regard to track changes in word document. I have attached document with track changes

Using Aspose, I want to provide an option for user to view “original” document or “No Mark up” document similar to word.

For that, I am using RevisionView.Original and RevisionsView.Final respectively for user options and show/parse through paragraphs.

However, though I apply “Original” or “Final” and parse paragraphs I am receiving same result
Program For Original::

doc.RevisionsView = RevisionsView.Original;
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    Console.WriteLine(para.Range.Text);
}

Expected output for Original:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.
Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.
Fusce est. Vivamus a tellus.

Code For Final:

doc.RevisionsView = RevisionsView.Final;
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    Console.WriteLine(para.Range.Text);
}

Expected output for Final :
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa.
sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.
Fusce est. Vivamus a tellus.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa

@crshekharam,

Please check if the following solution is acceptable for you?

Document doc = new Document("E:\\Temp\\raj track\\raj track.docx");

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    Console.WriteLine(para.Range.Text);
}

Console.WriteLine("--------------");

doc.AcceptAllRevisions();

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    Console.WriteLine(para.Range.Text);
}

This will not work for us. I don’t want to accept all revisions as it will remove all track changes. Moreover the code you have given before “AcceptAllRevisions” will display paragraphs of both “Original” and “Final”

@crshekharam,

We have logged your requirement/problem in our issue tracking system. Your ticket number is WORDSNET-20434. We will further look into the details of this and will keep you updated on the status of the linked issue. We apologize for any inconvenience.

@crshekharam,

Regarding WORDSNET-20434, it is to update you that the simplest way to get the desired result is by using the accept and reject approach. Please try running the following code:

Document doc = new Document("in.docx");

Console.WriteLine("No markup:");
Document noMarkupDoc = doc.Clone();
noMarkupDoc.Revisions.AcceptAll();
foreach (Paragraph para in noMarkupDoc.GetChildNodes(NodeType.Paragraph, true))
{
    Console.WriteLine(para.Range.Text);
}

Console.WriteLine("Original:");
Document originalDoc = doc.Clone();
originalDoc.Revisions.RejectAll();
foreach (Paragraph para in originalDoc.GetChildNodes(NodeType.Paragraph, true))
{
    Console.WriteLine(para.Range.Text);
}

I don’t want to accept/reject all revisions as it will remove all track changes.

@crshekharam,

I have logged your concerns in our issue tracking system and will keep you posted here on any further updates.

@crshekharam,

Regarding WORDSNET-20434, please note that accept/reject logic is very complex and there are many complex details as to how revisions are currently handled to get result similar to MS Word. So, I am afraid, accept and reject approach is the only option that we can suggest to you. You can clone Document object and do accept/reject in cloned object, this way original document will be untouched. Thanks for your understanding.

crshekharam:

doc.RevisionsView = RevisionsView.Final

Then what does this do “Document.RevisionsView Property” as given in
https://reference.aspose.com/words/net/aspose.words/document/revisionsview/

Thanks

@crshekharam,

In addition to the link you shared, please refer to the following section of documentation:

@crshekharam,

Just to update you that the Document.RevisionsView property is intended to select which version of formatting is shown by Font, ParagraphFormat, etc.

Hello
Can you give sample document used in this example
https://reference.aspose.com/words/net/aspose.words/document/revisionsview/

@crshekharam You can find all text document in our github:
https://github.com/aspose-words/Aspose.Words-for-.NET

Here is the document you are asking about: Revisions at list levels.docx (20.3 KB)

As per documentation, RevisionsView.Final and RevisionsView.Original are supported only for list labels. Is there any timeline to support other elements like normal runs, paragraphs, etc?

@crshekharam Document.RevisionsView property indented to select which version of formatting shown by Font, ParagraphFormat, etc. So it is not limited to list labels only.

Please find test document and code below

public static void TestRevisions(String FileIn)
{
    Document doc = new Document(FileIn);
    doc.RevisionsView = RevisionsView.Final;
    foreach (Run r in doc.GetChildNodes(NodeType.Run, true))
    {
        Console.WriteLine(r.Font.Name);
        Console.ReadLine();
    }
}

Output for this code is shown as Calibri instead of Times New Roman
test track changes.docx (12.0 KB)

@crshekharam Thank you for additional information. I have managed to reproduce the problem on my side. For a sake of correction it has been logged as WORDSNET-24532. We will keep you updated and let you know once the issue is resolved or we have more information for you.

The issues you have found earlier (filed as WORDSNET-24532) have been fixed in this Aspose.Words for .NET 23.1 update also available on NuGet.