• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
Namespace:  Microsoft.VisualBasic.FileIO

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手册上并没有写这块



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap