Export (0) Print
Expand All

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


Type: System.String

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


The target file is open or the path is incorrect.


The file path is null.

The deleted file cannot be recovered once deleted.

The How to: Delete Files and Directories in Isolated Storage 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()
        IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Assembly |

        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.
            // Confirm that no files remain.
            fileNames = isoFile.GetFileNames("*");
    catch (Exception e)


.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft