I'm trying to figure out how I can read and write params that gets stored in the applications isolated storage.
Right now im building a windows phone app, but since I want a win8 app to I figured I could do it in portable class library project, and found this awesome PCLStorage.
My Cache class looks atm like this for storing params:
public async static Task<string> GetParam(string name)
{
IFolder rootfolder = FileSystem.Current.LocalStorage;
IFolder folder = await rootfolder.GetFolderAsync("isostore");
IFile file = await folder.GetFileAsync(name);
return await file.ReadAllTextAsync();
}
public async static void SaveParam(string name, string param)
{
IFolder rootfolder = FileSystem.Current.LocalStorage;
IFolder folder = await rootfolder.CreateFolderAsync("isostore", CreationCollisionOption.OpenIfExists);
IFile file = await folder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);
await file.WriteAllTextAsync(param);
}
The write part is okey, it overrides if there is any. Its the reading part that is the problem. IFile and IFolder does not have any .Exists
functions (???) so what does it return if I call Get before Save?
I think in your case in the GetParam
method you should be calling CreateFolderAsync and CreateFileAsync with the CreationCollisionOption.OpenIfExists parameter. Then you shouldn't need to worry about creating them separately beforehand or catching exceptions that they do/don't exist.