我知道这听起来可能非常nooby,很抱歉提前,但我学习,我花了近2个小时试图找出如何没有结果做到这一点,现在...删除一个孤立的存储文件
我想知道如何去删除Windows Phone 7中的独立存储的特定文件。
在此先感谢!
我知道这听起来可能非常nooby,很抱歉提前,但我学习,我花了近2个小时试图找出如何没有结果做到这一点,现在...删除一个孤立的存储文件
我想知道如何去删除Windows Phone 7中的独立存储的特定文件。
在此先感谢!
只需致电IsolatedStorageFile.DeleteFile
即可。
例如:
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
storage.DeleteFile("backup.bak");
使用IsolatedStorageFile.DeleteFile
。
using(var store = IsolatedStorageFile.GetUserStoreForApplication())
store.DeleteFile("path.txt");
只是为了添加到现有的答案:记得来捕捉IsolatedStorageException,而不是一个IOException,你可能会使用到。
// you should add here try/catch blocks
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
store.DeleteFile("Your file Name string");
}
您可以检查这里的类: MSDN IsolatedStorageFile Class
谢谢,我想这和它的工作,但它抛出异常: System.ArgumentException”出现在mscorlib.dll System.IO.IsolatedStorage。 IsolatedStorageException – Jamie 2010-11-16 21:29:34
要记住的一件事是WP7模拟器在关闭时会抛出Isolated Storage。所以,如果你已经创建了这个文件,关闭了模拟器并尝试在下次运行时删除,你会发现一个异常。 – 2010-11-17 00:11:49