2017-06-26 49 views
1

我正在使用Word Interop工具更改现有Word文档的项目。但是,当我完成这些更改并保存数据时,我查看了这些属性,它显示我在当前时间进行了更改。有没有一种方法可以让我们说文档最近一个星期前被访问,在我做出更改并保存之后,它仍然显示文档是在一个星期前最后打开的?C#更改对word文档的修改吗?

+0

LastAccessed与LastModified不同。请检查LastModified数据时间,而不是LastAccessed。 –

+0

我希望保持上次访问和上次修改的时间与之前在文档打开并进行更改之前保持相同。 – Dylan

+0

你在哪里试图保持这两个信息? –

回答

0

我找到了答案。如果其他人有兴趣,我已经在下面发布了一个示例代码!它保留word文档的最后修改和最后访问的属性。

//filePath is a string with the location of your word document 
DateTime preserveAccess = File.GetLastAccessTime(filePath); 
DateTime preserveModify = File.GetLastWriteTime(filePath); 

//Some code to open the document, make changes, and then save it back 
//Now the last accessed and modified data will be different than before 

//You can set the last accessed and modified to the original that you 
//retrieved before making any changes to the document 

File.SetLastAccessTime(filePath, preserveAccess); 
File.SetLastWriteTime(filePath, preserveModify);