How to: Create Files and Directories in Isolated Storage

How to: Create Files and Directories in Isolated Storage


After you have obtained an isolated store, you can create directories and files for storing data. Within a store, file and directory names are specified with respect to the root of the virtual file system.

To create a directory, use the IsolatedStorageFile.CreateDirectory instance method. If you specify a subdirectory of an directory that doesn't exist, both directories are created. If you specify a directory that already exists, the method returns without creating a directory, and no exception is thrown. However, if you specify a directory name that contains invalid characters, an IsolatedStorageException exception is thrown.

To create a file, use the IsolatedStorageFile.CreateFile method.

In the Windows operating system, isolated storage file and directory names are case-insensitive. That is, if you create a file named ThisFile.txt, and then create another file named THISFILE.TXT, only one file is created. The file name keeps its original casing for display purposes.

The following code example illustrates how to create files and directories in an isolated store.

using System;
using System.IO;
using System.IO.IsolatedStorage;

public class CreatingFilesDirectories
    public static void Main()
        using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null))
            Console.WriteLine("Created directories.");

            Console.WriteLine("Created a new file in the root.");

            Console.WriteLine("Created a new file in the InsideDirectory.");
© 2016 Microsoft