Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IsolatedStorageFile.DeleteDirectory Method

Deletes a directory in the isolated storage scope.

Namespace:  System.IO.IsolatedStorage
Assembly:  mscorlib (in mscorlib.dll)

public void DeleteDirectory(
	string dir


Type: System.String

The relative path of the directory to delete within the isolated storage scope.


The directory could not be deleted.


The directory path was null.

A directory must be empty before it is deleted. The deleted directory cannot be recovered once deleted.

The How to: Delete Files and Directories in Isolated Storage example demonstrates the use of the DeleteDirectory method.

// This method deletes directories in the specified Isolated Storage, after first  
// deleting the files they contain. In this example, the Archive directory is deleted.  
// There should be no other directories in this Isolated Storage. 
public void DeleteDirectories()
        IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Assembly |
        String[] dirNames = isoFile.GetDirectoryNames("*");
        String[] fileNames = isoFile.GetFileNames("Archive\\*");

        // Delete all the files currently in the Archive directory. 

        if (fileNames.Length > 0)
            for (int i = 0; i < fileNames.Length; ++i)
                // Delete the files.
                isoFile.DeleteFile("Archive\\" + fileNames[i]);
            // Confirm that no files remain.
            fileNames = isoFile.GetFileNames("Archive\\*");

        if (dirNames.Length > 0)
            for (int i = 0; i < dirNames.Length; ++i)
                // Delete the Archive directory.
        dirNames = isoFile.GetDirectoryNames("*");
    catch (Exception e)

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
© 2018 Microsoft