C#更改对word文档的修改?

时间:2017-06-26 12:49:46

标签: c# visual-studio-2010 ms-word office-interop

我正在开发一个项目,我正在使用Word Interop工具更改现有的word文档。但是,当我完成这些更改并保存数据时,我会查看属性并显示我在当前时间进行了更改。有没有办法让我们说一周前最后一次访问该文档,在我进行更改并保存之后,它仍然显示该文档是在一周前最后一次打开的?

1 个答案:

答案 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);