AppData.Local
から xml ファイルを取得し、それをリストにシリアル化します
私がコーディング
したもの エラー部分:
List<myTask> AllTaskList = await objectStorageHelper.LoadAsync();
myTask は単純なクラスです。
public class myTask
{
public string myTitle { get; set; }
public string myDuetime { get; set; }
}
objectStorageHelper はCodePlexの HelpClass であり、LoadAsync 部分は以下のとおりです。
public async Task<T> LoadAsync()
{
try
{
StorageFile file = null;
StorageFolder folder = GetFolder(storageType);
file = await folder.GetFileAsync(FileName());
//file = await folder.CreateFileAsync("BetterTask.xml", CreationCollisionOption.OpenIfExists);
IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read);
Stream inStream = Task.Run(() => readStream.AsStreamForRead()).Result;
return (T)serializer.Deserialize(inStream);
}
catch (FileNotFoundException)
{
//file not existing is perfectly valid so simply return the default
return default(T);
//Interesting thread here: How to detect if a file exists (http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/1eb71a80-c59c-4146-aeb6-fefd69f4b4bb)
//throw;
}
catch (Exception)
{
//Unable to load contents of file
throw;
}
}
エラーとは
タイプ 'System.UnauthorizedAccessException' の例外が mscorlib.dll で発生しましたが、ユーザー コードで処理されませんでした
追加情報: アクセスが拒否されました。 (HRESULT:0x80070005 (E_ACCESSDENIED) からの例外)
この例外のハンドラがあれば、プログラムは安全に続行できます。
--
これはなぜですか?<br/> このヘルプ クラスを使用して、ファイルに正常に書き込むことができます。
しかし、ファイルを読み取る権限がないのはなぜですか?
それを解決する方法は?