IsolatedStorageFile.DeleteFile Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Deletes a file in the isolated store.

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

Syntax

Public Sub DeleteFile ( _
    file As String _
)
public void DeleteFile(
    string file
)

Parameters

  • file
    Type: System..::.String
    The relative path of the file to delete within the isolated store.

Exceptions

Exception Condition
IsolatedStorageException

The store has been removed.

-or-

Unable to delete the file.

-or-

Isolated storage is disabled.

ArgumentException

file is badly formed.

ArgumentNullException

file is nullNothingnullptra null reference (Nothing in Visual Basic).

ObjectDisposedException

The store has been disposed.

Remarks

The deleted file cannot be recovered once deleted.

Note

File deletions are subject to intermittent failures because files can be in use simultaneously by operating system features such as virus scanners and file indexers. This is especially true for recently created files. For these reasons, it is important to add code to the code block that handles the IsolatedStorageException to retry deleting the file or log a failure.

Examples

The following example deletes a file from the store. This example is part of a larger example provided for IsolatedStorageFile class.

' Delete a file.
Try
    If store.FileExists(filePath) Then
        store.DeleteFile(filePath)
    End If
Catch ex As IsolatedStorageException
    sb.AppendLine(ex.Message)
End Try
// Delete a file.
try
{
    if (store.FileExists(filePath))
    {
        store.DeleteFile(filePath);
    }
}
catch (IsolatedStorageException ex)
{
    sb.AppendLine(ex.Message);
}

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

IsolatedStorageFile Class

System.IO.IsolatedStorage Namespace