如果應用程式使用需要私用 (Private) 資料存放區的協力廠商組件,可使用隔離儲存區來儲存私用資料。 依據使用者、定義域和組件的隔離會確保只有指定組件中的程式碼可以存取資料,並且只有當在組件建立存放區時執行的應用程式使用組件時,以及只有當為其建立存放區的使用者執行應用程式時。 依據使用者、定義域和組件的隔離可避免協力廠商組件洩漏資料給其他應用程式。 這個隔離類型應該是您的預設選擇,如果您知道要使用隔離儲存區,但不確定要使哪個隔離類型的話。 呼叫 IsolatedStorageFile 的靜態 GetStore 方法並傳入使用者、定義域和組件,IsolatedStorageScope 會傳回這種隔離類型的儲存區。
下列程式碼範例擷取使用者、定義域和組件所隔離的存放區。 存放區可以透過 isoFile 物件來存取。
Dim isoFile As IsolatedStorageFile = _
IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or _
IsolatedStorageScope.Domain Or _
IsolatedStorageScope.Assembly, Nothing, Nothing)
IsolatedStorageFile isoFile =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Domain |
IsolatedStorageScope.Assembly, null, null);
IsolatedStorageFile^ isoFile =
IsolatedStorageFile::GetStore(IsolatedStorageScope::User |
IsolatedStorageScope::Domain |
IsolatedStorageScope::Assembly, (Type^)nullptr, (Type^)nullptr);
另一個方法可當做捷徑使用,如下列程式碼範例所示。 這個捷徑不能用來開啟能夠漫遊的存放區;在此類情況中請使用 GetStore。
Dim isoFile As IsolatedStorageFile = _
IsolatedStorageFile.GetUserStoreForDomain()
IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForDomain();
IsolatedStorageFile^ isoFile = IsolatedStorageFile::GetUserStoreForDomain();