Word和Excel文件版本

跟踪Excel和Word文件版本的最佳方法是什么?

上次修改的date不适用于我,因为只要将文件复制到新位置,它就会更改。

我正在使用C#。

Thx任何答复。

也许Aspose可以帮助:
http://www.aspose.com/docs/display/wordsnet/Working+with+Document+Properties

我会假设在Open XML SDK中有类似的东西,但没有检查。

Office文档中有一个DateLastSaved OLE文档属性。 有几种方法可以获取Office文档属性。 我更喜欢使用Micorsoft DSO DLL来访问这些属性。 您可以从http://www.microsoft.com/en-us/download/details.aspx?id=8422获取该文件。

这是一个使用DSO DLL的示例

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

如果您更喜欢使用Windows API,下面是一个示例, 使用WindowsAPI代码包在服务器上读取MS Office XML文档属性失败

根据您拥有的用户数量以及审计跟踪的重要性,您可能会考虑查看正式的版本控制工具。 其中有一些免费版本的小团体数量有限的文件和工具,如混帐或颠覆是免费的(至less他们可以)。 这些工具可以给你一切,人物,date,时间内容,以及方便的项目,如回滚和比较版本…当然可能是矫枉过正…

我希望FileInfo的属性LastWriteTime应该解决这个问题

在这个例子中, 模式可以像“Letter.doc”或“Worksheet.xls”

PATH_TO_TRAKING_FOLDER是可以包含跟踪的word / excel文件的不同版本的基础文件夹

 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) ; } } }