基本上,我想在实际尝试打开文件之前检查是否有权打开文件; 除非必须,否则我不想使用try/catch进行此检查.有没有我可以检查的文件访问属性?
我有一个程序可以执行不同的操作,我的问题与网络映射驱动器或共享文件夹中的访问文件有关
程序可以从网络运行文件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;
}
Run Code Online (Sandbox Code Playgroud)
谢谢