Export (0) Print
Expand All

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.

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);
    }
}
Show:
© 2014 Microsoft