EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

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
)
public void DeleteDirectory (
	String dir
)
public function DeleteDirectory (
	dir : String
)
Not applicable.

Parameters

dir

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

Exception typeCondition

IsolatedStorageException

The directory could not be deleted.

ArgumentNullException

The directory path was a null reference (Nothing in Visual Basic).

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

The Deleting Files and Directories 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());
    }
}

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Ajouts de la communauté

Afficher:
© 2014 Microsoft