Replacing or recreating a file in Windows 8 RT keeps the old DateCreated value

时光怂恿深爱的人放手 提交于 2020-01-03 19:06:17

问题


I'm attempting to cache data in a file for a Windows Store app, and using the DateCreated value to determine if it is out of date.

I first tried doing this:

    var file = await rootFolder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);

    FileIO.WriteTextAsync(file, contents);

but when it saves the file only the DateModified value is changed, even though the comments for the ReplaceExisting option clearly state that it recreates the file and replaces an existing one.

So I decided to force it to delete the file and recreate it with this:

    var file = await rootFolder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);

// force delete because windows rt is not doing what it's supposed to in the line above!!
await file.DeleteAsync();
file = await rootFolder.CreateFileAsync(filename);

FileIO.WriteTextAsync(file, contents);

but amazingly, I still get the same result! The file is deleted and recreated with the OLD CREATION DATE!

Is this a bug, or am I doing something wrong here?


回答1:


This is by design, a feature called "File system tunneling". This KB article explains the behavior and rationale.

The workaround it documents requires registry editing, clearly you cannot rely on that in a Store application. You'll need to find a workaround, like using the last-written timestamp or alternating between two files or keep track of age in a separate file.




回答2:


Thanks for the comments everyone, it turns out the Modified date IS available but you have to get it through the GetBasicPropertiesAsync() method as shown here: http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.fileproperties.basicproperties.datemodified.aspx



来源:https://stackoverflow.com/questions/14133560/replacing-or-recreating-a-file-in-windows-8-rt-keeps-the-old-datecreated-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!