Export (0) Print
Expand All

FileSystem.DeleteFile Method (String)

Deletes a file.

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static void DeleteFile(
	string file
)

Parameters

file
Type: System.String

Name and path of the file to be deleted.

ExceptionCondition
ArgumentException

The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; it has a trailing slash where a file must be specified; or it is a device path (starts with \\.\).

ArgumentNullException

file is Nothing or an empty string.

PathTooLongException

The path exceeds the system-defined maximum length.

NotSupportedException

A file or directory name in the path contains a colon (:) or is in an invalid format.

IOException

The file is in use.

SecurityException

The user lacks necessary permissions to view the path.

FileNotFoundException

The file does not exist.

UnauthorizedAccessException

The user does not have permission to delete the file or the file is read-only.

The following table lists an example of a task involving the My.Computer.FileSystem.DeleteFile method.

This example deletes the file Test.txt.

My.Computer.FileSystem.DeleteFile("C:\test.txt")

This example deletes the file Test.txt and allows the user to confirm that the file should be deleted.

My.Computer.FileSystem.DeleteFile(
  "C:\test.txt",
  FileIO.UIOption.AllDialogs,
  FileIO.RecycleOption.SendToRecycleBin,
  FileIO.UICancelOption.ThrowException)

This example deletes the file Test.txt and sends it to the Recycle Bin.

My.Computer.FileSystem.DeleteFile(
  "C:\test.txt",
  FileIO.UIOption.OnlyErrorDialogs,
  FileIO.RecycleOption.SendToRecycleBin,
  FileIO.UICancelOption.ThrowException)

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Show:
© 2014 Microsoft