2017-06-26 58 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);