3

我正在尝试将数据缓存在 Windows 应用商店应用程序的文件中,并使用 DateCreated 值来确定它是否已过期。

我首先尝试这样做:

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

    FileIO.WriteTextAsync(file, contents);

但是当它保存文件时,仅更改 DateModified 值,即使 ReplaceExisting 选项的注释清楚地表明它会重新创建文件并替换现有文件。

所以我决定强制它删除文件并用这个重新创建它:

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

但令人惊讶的是,我仍然得到相同的结果!该文件被删除并使用旧创建日期重新创建!

这是一个错误,还是我在这里做错了什么?

4

2 回答 2

2

这是设计使然,称为“文件系统隧道”的功能。此知识库文章解释了行为和基本原理。

它记录的解决方法需要注册表编辑,显然您不能在 Store 应用程序中依赖它。您需要找到一种解决方法,例如使用最后写入的时间戳或在两个文件之间交替或在单独的文件中跟踪年龄。

于 2013-01-03T07:05:30.547 回答
1

感谢大家的评论,事实证明修改日期可用,但您必须通过 GetBasicPropertiesAsync() 方法获取它,如下所示:http: //msdn.microsoft.com/en-us/library/windows/apps/ windows.storage.fileproperties.basicproperties.datemodified.aspx

于 2013-01-03T15:23:12.483 回答