Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
public static void DeleteFile( string file, UIOption showUI, RecycleOption recycle, UICancelOption onUserCancel )
Parameters
- file
- Type: System.String
Name and path of the file to be deleted.
- showUI
- Type: Microsoft.VisualBasic.FileIO.UIOption
Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs.
- recycle
- Type: Microsoft.VisualBasic.FileIO.RecycleOption
Whether or not the deleted file should be sent to the Recycle Bin. Default is RecycleOption.DeletePermanently.
- onUserCancel
- Type: Microsoft.VisualBasic.FileIO.UICancelOption
Specifies whether or not an exception is thrown when the user cancels the operation. Default is UICancelOption.ThrowException.
Exception | Condition |
---|---|
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. |
OperationCanceledException |
The user cancelled the operation and onUserCancel is set to UICancelOption.ThrowException. //重点,由此判断用户单击取消按钮时触发的异常,msdn手册上并没有写这块 |