关于C#判断的问题~~~~~~

来源:百度知道 编辑:UC知道 时间:2024/06/28 03:43:18
System.IO.File.Move(b.Text, asg);
不就是把b.Text移动到asg.

可是如何判断移动成功 就 messagebox("移动成功");
失败就messagebox("移动失败");


try
{
System.IO.File.Move(b.Text, asg);
messagebox("移动成功");
}
catch
{
messagebox("失败");
}

try
{System.IO.File.Move(b.Text, asg);
messagebox("移动成功");
}
catch(Exception e)
{
messagebox("文件移动失败");
}

通过try catch来判断。异常出现的原因如下:
异常 条件
IOException 目标文件已经存在。

ArgumentNullException sourceFileName 或 destFileName 为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing)。

ArgumentException sourceFileName 或 destFileName 是零长度字符串、只包含空白或者包含在 InvalidPathChars 中定义的无效字符。

UnauthorizedAccessException 调用方没有所要求的权限。

FileNotFoundException 未找到 sourceFileName。

PathTooLongException 指定的路径、文件名或者两者都超出了系统定义的最大长度。例如,在基于 Windows 的平台上,路径必须小于 248 个字符,文件名必须小于 260 个字符。

DirectoryNotFoundException sourceFileName 或 destFileName 中指定的路径无效(例如,它位于未映射的驱动器上)。

NotSupportedException sourceFileName 或 destFil