0

In office 2003, we can save different versions of the word document in the same .doc file. But this versions feature is removed from 2007.

Is there any option to detect whether the .doc file is having any versions and extract the versions to different files through our code in c#.

encrypted name
  • 149
  • 3
  • 17
  • You may be interested in `Versions` from Microsoft.Office.Interop.Word assembly (https://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.versions%28v=office.11%29.aspx) – Nicolas R Feb 24 '15 at 15:26

1 Answers1

1

I would look into this bit of info:

Microsoft Office Library

It has a good bit of information on getting the version from the Document.

First thing you need to do is add a reference to:

Microsoft.Office.Interop.Word;

Then instantiate a document from the file you want to extract the Version from:

    Application application = new Application();
    Document document = new Document();

Open the Document:

    this.application.Documents.Open(@"C:\Users\...\nameOfDoc.doc", ReadOnly: true);
    document = this.application.Documents["nameOfDoc.doc"];

Extract your Version:

    String documentVersion;
    if (document.Versions.Count > 0)
    {
            documentVersion = document.Versions[document.Versions.Count - 1].ToString();
    }
    else
    {
            documentVersion = "No Versioning";
    }

The ReadOnly: true is not required and can be set to false depending on what you want to do. I generally don't like to have more power than necessary.

Also, the [document.Versions.Count - 1] should get you the latest Version according to what I read in the documentation (not tested).

I hope this helps you! If not, it should get you on the right track.

Kaden.Goodell
  • 162
  • 1
  • 8