How to: Enumerate Stores for Isolated Storage

You can enumerate all isolated stores for the current user by using the IsolatedStorageFile.GetEnumerator static method. This method takes an IsolatedStorageScope value and returns an IsolatedStorageFile enumerator. To enumerate stores, you must have the IsolatedStorageFilePermission permission that specifies the AdministerIsolatedStorageByUser value. If you call the GetEnumerator method with the User value, it returns an array of IsolatedStorageFile objects that are defined for the current user.

Example

The following code example obtains a store that is isolated by user and assembly, creates a few files, and retrieves those files by using the GetEnumerator method.

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

See Also

IsolatedStorageFile
Isolated Storage