public static class IsolatedStorageHelper
{
public static void CreateDirectory(string path)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (storage.DirectoryExists(path) == false) storage.CreateDirectory(path);
}
}
public static void DeleteDirectory(string path)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (storage.DirectoryExists(path) == true) storage.DeleteDirectory(path);
else throw new DirectoryNotFoundException(path);
}
}
public static string[] ListDirectories(string pattern)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (pattern != null) return storage.GetDirectoryNames(pattern);
else return storage.GetDirectoryNames();
}
}
public static string[] ListFiles(string pattern)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (pattern != null) return storage.GetFileNames(pattern);
else return storage.GetFileNames();
}
}
public static void SaveData(string path, string data)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (StreamWriter sw = new StreamWriter(storage.OpenFile(path, FileMode.Append, FileAccess.Write)))
{
sw.Write(data);
sw.Close();
}
}
}
public static string LoadData(string path)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (storage.FileExists(path))
{
using (StreamReader sw = new StreamReader(storage.OpenFile(path, FileMode.Open, FileAccess.Read)))
{
return sw.ReadToEnd();
}
}
else throw new FileNotFoundException(path);
}
}
public static void DeleteFile(string path)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (storage.FileExists(path)) storage.DeleteFile(path);
else throw new FileNotFoundException(path);
}
}
}