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

C# Change revisions made to word document?

我正在开展一个项目,我正在使用 Word Interop 工具对现有 Word 文档进行更改。然而,当我完成这些更改并保存数据后,我查看了属性,它显示我在当前时间进行了更改。有没有办法假设文档上次访问是在一周前,在我进行更改并保存后,它仍然显示文档上次打开是在一周前?

我找到了答案。如果其他人有兴趣,我已经在下面发布了示例代码!它保留了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);