您的位置:首页 > 编程语言 > C#

C# 删除文件、文件到到回收站及异常判断

2013-05-17 09:37 381 查看
Namespace: Microsoft.VisualBasic.FileIO

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

Syntax

C#

C++

F#

VB

public static void DeleteFile(
string file,
UIOption showUI,
RecycleOption recycle,
UICancelOption onUserCancel
)



Parameters

fileType: System.String

Name and path of the file to be deleted.

showUIType: Microsoft.VisualBasic.FileIO.UIOption

Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs.

recycleType: Microsoft.VisualBasic.FileIO.RecycleOption

Whether or not the deleted file should be sent to the Recycle Bin. Default is RecycleOption.DeletePermanently.

onUserCancelType: Microsoft.VisualBasic.FileIO.UICancelOption

Specifies whether or not an exception is thrown when the user cancels the operation. Default is UICancelOption.ThrowException.

Exceptions

ExceptionCondition
ArgumentExceptionThe 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 \\.\).
ArgumentNullExceptionfile is Nothing or an empty string.
PathTooLongExceptionThe path exceeds the system-defined maximum length.
NotSupportedExceptionA file or directory name in the path contains a colon (:) or is in an invalid format.
IOExceptionThe file is in use.
SecurityExceptionThe user lacks necessary permissions to view the path.
FileNotFoundExceptionThe file does not exist.
UnauthorizedAccessExceptionThe user does not have permission to delete the file or the file is read-only.
OperationCanceledExceptionThe user cancelled the operation and onUserCancel is set to UICancelOption.ThrowException.

//重点,由此判断用户单击取消按钮时触发的异常,msdn手册上并没有写这块
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: