【发布时间】:2012-09-06 11:22:51
【问题描述】:
我正在尝试写入和读取 Win8 的本地存储。使用帮助程序我能够成功写入我的机器,但读取 .xml 文件给了我一个:System.UnauthorizedAccessException 发生在 mscorlib.dll 错误
我创建了一个代码粘贴,以便您查看我的代码。
代码在这里失败:
public async static Task<object> LoadData(string path, System.Type type)
{
var _Folder = Windows.Storage.ApplicationData.Current.LocalFolder;
try
{
var _File = await Folder.GetFileAsync(path);
using (IInputStream inStream = await _File.OpenSequentialReadAsync())
{
// Deserialize the Session State
XmlSerializer x = new XmlSerializer(type);
return x.Deserialize(inStream.AsStreamForRead());
}
}
catch (Exception ex)
{
MessageDialog dialog = new MessageDialog(ex.Message.ToString());
dialog.ShowAsync();
return null;
}
}
具体在这一行:
using (IInputStream inStream = await _File.OpenSequentialReadAsync())
如果您对我做错了什么有任何想法,那将对我有很大帮助。
我在 Release Preview 中执行此操作。如果我需要提供任何其他系统信息,请告诉我。
【问题讨论】:
-
你忘了实际使用 _Folder 变量。