I get the following exception when I try to delete a directory in Isolated Storage in Windows Phone 7:
An error occurred while accessing IsolatedStorage.
there is no inner exception.
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
isf.DeleteDirectory(dir.TrimEnd('/'));
}
Notes:
Any idea?
Thanks.
Ok, problem solved, problem was that files were not being deleted correctly. The reason I was confused is that IsolatedStorageFile class does not warn you when you are deleting an invalid file. here is the correct code and some notes:
public static void DeleteDirectoryRecursive(this IsolatedStorageFile isf, string dir)
{
foreach (var file in isf.GetFileNames(dir))
{
isf.DeleteFile(dir + file);
}
foreach (var subdir in isf.GetDirectoryNames(dir))
{
isf.DeleteDirectoryRecursive(dir + subdir + "\\");
}
isf.DeleteDirectory(dir.TrimEnd('\\'));
}
Notes: