作法:刪除隔離儲存區中的存放區
IsolatedStorageFile 類別提供兩種方法來刪除隔離儲存區檔案:
執行個體方法 Remove() 不接受任何引數,並刪除呼叫它的存放區。 這個作業不需要使用權限。 能夠存取存放區的任何程式碼,都可以刪除在它之內的任何或所有資料。
靜態方法 Remove(IsolatedStorageScope) 會接受 User 列舉值,並刪除執行程式碼之使用者的所有存放區。 這項作業需要 IsolatedStorageFilePermission 值的 AdministerIsolatedStorageByUser 權限。
範例
下列程式碼範例將示範靜態及執行個體 Remove 方法的使用方式。 該類別取得兩個存放區,一個為使用者和組件所隔離,而另一個為使用者、定義域和組件所隔離。 接著呼叫隔離儲存區檔案 Remove() 的 isoStore1
方法,刪除使用者、定義域和組件存放區。 然後,使用者所有剩下的存放區是以呼叫靜態方法 Remove(IsolatedStorageScope)的方式刪除。
using namespace System;
using namespace System::IO::IsolatedStorage;
public ref class DeletingStores
{
public:
static void Main()
{
// Get a new isolated store for this user, domain, and assembly.
// Put the store into an IsolatedStorageFile object.
IsolatedStorageFile^ isoStore1 = IsolatedStorageFile::GetStore(IsolatedStorageScope::User |
IsolatedStorageScope::Domain | IsolatedStorageScope::Assembly, (Type ^)nullptr, (Type ^)nullptr);
Console::WriteLine("A store isolated by user, assembly, and domain has been obtained.");
// Get a new isolated store for user and assembly.
// Put that store into a different IsolatedStorageFile object.
IsolatedStorageFile^ isoStore2 = IsolatedStorageFile::GetStore(IsolatedStorageScope::User |
IsolatedStorageScope::Assembly, (Type ^)nullptr, (Type ^)nullptr);
Console::WriteLine("A store isolated by user and assembly has been obtained.");
// The Remove method deletes a specific store, in this case the
// isoStore1 file.
isoStore1->Remove();
Console::WriteLine("The user, domain, and assembly isolated store has been deleted.");
// This static method deletes all the isolated stores for this user.
IsolatedStorageFile::Remove(IsolatedStorageScope::User);
Console::WriteLine("All isolated stores for this user have been deleted.");
} // End of Main.
};
int main()
{
DeletingStores::Main();
}
using System;
using System.IO.IsolatedStorage;
public class DeletingStores
{
public static void Main()
{
// Get a new isolated store for this user, domain, and assembly.
// Put the store into an IsolatedStorageFile object.
IsolatedStorageFile isoStore1 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);
Console.WriteLine("A store isolated by user, assembly, and domain has been obtained.");
// Get a new isolated store for user and assembly.
// Put that store into a different IsolatedStorageFile object.
IsolatedStorageFile isoStore2 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly, null, null);
Console.WriteLine("A store isolated by user and assembly has been obtained.");
// The Remove method deletes a specific store, in this case the
// isoStore1 file.
isoStore1.Remove();
Console.WriteLine("The user, domain, and assembly isolated store has been deleted.");
// This static method deletes all the isolated stores for this user.
IsolatedStorageFile.Remove(IsolatedStorageScope.User);
Console.WriteLine("All isolated stores for this user have been deleted.");
} // End of Main.
}
Imports System.IO.IsolatedStorage
Public Class DeletingStores
Public Shared Sub Main()
' Get a new isolated store for this user, domain, and assembly.
' Put the store into an IsolatedStorageFile object.
Dim isoStore1 As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
IsolatedStorageScope.Domain Or IsolatedStorageScope.Assembly, Nothing, Nothing)
Console.WriteLine("A store isolated by user, assembly, and domain has been obtained.")
' Get a new isolated store for user and assembly.
' Put that store into a different IsolatedStorageFile object.
Dim isoStore2 As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
IsolatedStorageScope.Assembly, Nothing, Nothing)
Console.WriteLine("A store isolated by user and assembly has been obtained.")
' The Remove method deletes a specific store, in this case the
' isoStore1 file.
isoStore1.Remove()
Console.WriteLine("The user, domain, and assembly isolated store has been deleted.")
' This static method deletes all the isolated stores for this user.
IsolatedStorageFile.Remove(IsolatedStorageScope.User)
Console.WriteLine("All isolated stores for this user have been deleted.")
End Sub
End Class