Question

What is the best way to keep track of Excel and Word file versions.

The date last modified is not working for me because it changes as soon as you copy the file to a new location.

I am using c#.

Thx for any replies.

No correct solution

OTHER TIPS

Maybe Aspose can help:
http://www.aspose.com/docs/display/wordsnet/Working+with+Document+Properties

I would assume that there is something similar in the Open XML SDK, but didn't check.

There is a DateLastSaved OLE document property in Office documents. There are a couple of ways to get Office document properties. I prefer using the Micorsoft DSO DLL to access these properties. You can get the file from http://www.microsoft.com/en-us/download/details.aspx?id=8422.

Here is a sample using the DSO DLL

DSOFile.OleDocumentPropertiesClass oleDocumentPropertiesClass = 
                       new DSOFile.OleDocumentPropertiesClass();
oleDocumentPropertiesClass.Open("C:\\My Documents\\some excel file.xlsx");
MessageBox.Show(oleDocumentPropertiesClass.SummaryProperties.DateLastSaved.ToString());

If you prefer to use the windows API, here is a sample for that, Reading MS Office XML document properties using WindowsAPI Code Pack fails on server

Depending on the number of users you have, and how important the audit trail you may consider looking at a formal version control tool. Quite a few of them have free versions for smaller groups with limited numbers of files and tools like git or subversion are free (at least they can be). These tools can give you everything, person, date, time content, plus handy items like rollback and comparing versions...could be overkill of course...

I thik that the property LastWriteTime of the FileInfo should solve this

In this example pattern can be something like "Letter.doc" or "Worksheet.xls"

and PATH_TO_TRAKING_FOLDER is the base folder that can contains the different versions of the word/excel files that you are tracking

using System.IO;

class Foo
{

    public method Bla()
    {
        DirectoryInfo dir;
        List<FileInfo> lstFiles;
        string pattern ;
        string line ;

            //pattern can be something like "Letter.doc" or "Worksheet.xls"
        pattern = "OfficeFile.extension" ;

            //is the base folder that can contains the different versions of the word/excel files that you are tracking
        dir = new DirectoryInfo("PATH_TO_TRAKING_FOLDER");

        lstFiles = new List<FileInfo>(dir.EnumerateFiles(pattern, SearchOption.AllDirectories).OrderBy(x => x.LastWriteTime) ;

        foreach(FileInfo fi in lstFiles)
        {
            line = Strin.format("{0}:{1}", fi.Name,fi.LastWriteTime) ;
            Console.WriteLine(line) ;
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top