在Windows 8 RT中替换或重新创建文件将保留旧的DateCreated值 [英] Replacing or recreating a file in Windows 8 RT keeps the old DateCreated value

查看:190
本文介绍了在Windows 8 RT中替换或重新创建文件将保留旧的DateCreated值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试缓存Windows Store应用程序的文件中的数据,并使用DateCreated值确定它是否过期。

我第一次尝试这样做:

$ $ $ code var文件=等待rootFolder.CreateFileAsync(文件名,Windows.Storage.CreationCollisionOption.ReplaceExisting);

FileIO.WriteTextAsync(file,contents);

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



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

  var file =等待rootFolder.CreateFileAsync(文件名,Windows.Storage.CreationCollisionOption.ReplaceExisting); 

//强制删除,因为windows rt没有在上面的行中做它应该做的事情!
等待file.DeleteAsync();
file =等待rootFolder.CreateFileAsync(filename);

FileIO.WriteTextAsync(file,contents);

但令人惊讶的是,我仍然得到相同的结果!该文件被删除,并重新创建OLD CREATION DATE!



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

解决方案

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


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?

解决方案

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

这篇关于在Windows 8 RT中替换或重新创建文件将保留旧的DateCreated值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆