2010-11-16 78 views
8

我知道這聽起來可能非常nooby,很抱歉提前,但我學習,我花了近2個小時試圖找出如何沒有結果做到這一點,現在...刪除一個孤立的存儲文件

我想知道如何去刪除Windows Phone 7中的獨立存儲的特定文件。

在此先感謝!

回答

10

只需致電IsolatedStorageFile.DeleteFile即可。

例如:

IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication(); 
storage.DeleteFile("backup.bak"); 
+0

謝謝,我想這和它的工作,但它拋出異常: System.ArgumentException」出現在mscorlib.dll System.IO.IsolatedStorage。 IsolatedStorageException – Jamie 2010-11-16 21:29:34

+3

要記住的一件事是WP7模擬器在關閉時會拋出Isolated Storage。所以,如果你已經創建了這個文件,關閉了模擬器並嘗試在下次運行時刪除,你會發現一個異常。 – 2010-11-17 00:11:49

0

只是爲了添加到現有的答案:記得來捕捉IsolatedStorageException,而不是一個IOException,你可能會使用到。

2
// you should add here try/catch blocks 

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
store.DeleteFile("Your file Name string"); 
} 

您可以檢查這裏的類: MSDN IsolatedStorageFile Class