C# 删除文件、文件到到回收站及异常判断
2013-05-17 09:37
381 查看
Namespace: Microsoft.VisualBasic.FileIO
Assembly: Microsoft.VisualBasic (in
Microsoft.VisualBasic.dll)
Syntax
C#
C++
F#
VB
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
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.StringName 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
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手册上并没有写这块 |
相关文章推荐
- C# 删除文件、文件到到回收站及异常判断
- C# 删除文件和目录到回收站
- C#判断文件是否存在然后执行删除
- C#删除文件和文件夹到回收站的代码
- C# 删除文件和文件夹到回收站
- c# 如何将文件删除到回收站(文件操作)
- C#删除文件直接到回收站,而不是直接删除
- C#.NET 删除文件到回收站
- C#删除文件和文件夹到回收站
- C#删除文件和文件夹到回收站
- C# 把文件和文件夹 放到回收站 (出现Unknown err (0x402) 无法删除 文件:无法读取源文件或磁盘 解决)
- c#删除文件或者目录到回收站
- C#引用Microsoft.VisualBasic将目录或文件删除到回收站。
- C#删除文件夹和文件到回收站示例
- C#删除文件和文件夹到回收站
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- 不用软件,对回收站删除文件后的恢复(windows 高级技巧)
- WPF中Image控件的Source属性,删除此Source所属目录时提示文件被占用的异常
- 牛客网Java刷题知识点之File对象常用功能:获取文件名称、获取文件路径、获取文件大小、获取文件修改时间、创建与删除、判断、重命名、查看系统根目录、容量获取、获取某个目录下内容、过滤器
- ubuntu创建、删除文件及文件夹,强制清空回收站方法