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
)

Parameters

dir
Type: System.String

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

ExceptionCondition
IsolatedStorageException

The directory could not be deleted.

ArgumentNullException

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()
{
    try
    {
        IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Assembly |
            IsolatedStorageScope.Domain,
            typeof(System.Security.Policy.Url),
            typeof(System.Security.Policy.Url));
        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("*");
        isoFile.Remove();
    }
    catch (Exception e)
    {
        Console.WriteLine(e.ToString());
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft