Porady: wykazywanie magazynów dla izolowanego magazynu
Przy użyciu metody statycznej można wyliczyć wszystkie izolowane magazyny dla bieżącego IsolatedStorageFile.GetEnumerator użytkownika. Ta metoda przyjmuje IsolatedStorageScope wartość i zwraca IsolatedStorageFile moduł wyliczający. Aby wyliczyć magazyny, musisz mieć IsolatedStorageFilePermission uprawnienie określające AdministerIsolatedStorageByUser wartość. Jeśli wywołasz metodę GetEnumerator z User wartością, zwraca ona tablicę IsolatedStorageFile obiektów zdefiniowanych dla bieżącego użytkownika.
Przykład
Poniższy przykład kodu uzyskuje magazyn, który jest izolowany przez użytkownika i zestaw, tworzy kilka plików i pobiera te pliki przy użyciu GetEnumerator metody .
using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections;
public class EnumeratingStores
{
public static void Main()
{
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null))
{
isoStore.CreateFile("TestFileA.Txt");
isoStore.CreateFile("TestFileB.Txt");
isoStore.CreateFile("TestFileC.Txt");
isoStore.CreateFile("TestFileD.Txt");
}
IEnumerator allFiles = IsolatedStorageFile.GetEnumerator(IsolatedStorageScope.User);
long totalsize = 0;
while (allFiles.MoveNext())
{
IsolatedStorageFile storeFile = (IsolatedStorageFile)allFiles.Current;
totalsize += (long)storeFile.UsedSize;
}
Console.WriteLine("The total size = " + totalsize);
}
}
Imports System.IO
Imports System.IO.IsolatedStorage
Module Module1
Sub Main()
Using isoStore As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly, Nothing, Nothing)
isoStore.CreateFile("TestFileA.Txt")
isoStore.CreateFile("TestFileB.Txt")
isoStore.CreateFile("TestFileC.Txt")
isoStore.CreateFile("TestFileD.Txt")
End Using
Dim allFiles As IEnumerator = IsolatedStorageFile.GetEnumerator(IsolatedStorageScope.User)
Dim totalsize As Long = 0
While (allFiles.MoveNext())
Dim storeFile As IsolatedStorageFile = CType(allFiles.Current, IsolatedStorageFile)
totalsize += CType(storeFile.UsedSize, Long)
End While
Console.WriteLine("The total size = " + totalsize.ToString())
End Sub
End Module