Windows apps
Collapse the table of content
Expand the table of content
Information
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.DeleteFile Method

Deletes a file in the isolated storage scope.

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

public void DeleteFile (
	string file
)
public void DeleteFile (
	String file
)
public function DeleteFile (
	file : String
)
Not applicable.

Parameters

file

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

Exception typeCondition

IsolatedStorageException

The target file is open or the path is incorrect.

ArgumentNullException

The file path is a null reference (Nothing in Visual Basic).

The deleted file cannot be recovered once deleted.

The Deleting Files and Directories example demonstrates the use of the DeleteFile method.

The following code example uses the DeleteFile method to delete a number of files in isolated storage.

public void DeleteFiles()
{
    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("*");

        // List the files currently in this Isolated Storage.
        // The list represents all users who have personal
        // preferences stored for this application.
        if (fileNames.Length > 0)
        {
            for (int i = 0; i < fileNames.Length; ++i)
            {
                // Delete the files.
                isoFile.DeleteFile(fileNames[i]);
            }
            // Confirm that no files remain.
            fileNames = isoFile.GetFileNames("*");
        }
    }
    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

Community Additions

Show:
© 2017 Microsoft