【发布时间】:2011-04-21 19:35:40
【问题描述】:
我有一个程序可以做不同的事情我的问题与访问网络映射驱动器或共享文件夹中的文件有关
程序可以从网络(网络映射驱动器或共享文件夹)运行文件 msi/exe 程序可以从网络复制文件(网络映射驱动器或共享文件夹)
在尝试运行或复制之前如何检查文件是否可访问(以防网络断开或任何其他网络问题)?
File.Exists();够了吗
这是我的代码示例:
public static bool FileIsOk(string path)
{
try
{
FileInfo finfo = new FileInfo(path);
if (finfo.Exists)
{
return true;
}
MessageBox.Show("file does not exist, or there is a problem with the network preventing access to the file!");
return false;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return false;
}
谢谢
【问题讨论】:
-
File.Exists() 将是要走的路,除非您需要检查某些权限?
-
检查文件/文件夹权限:stackoverflow.com/questions/3456397/…
标签: c# file networking file-io