我有一個程序,做不同的事情,我的問題是訪問網絡映射驅動器或共享文件夾檢查文件是否是共享網絡驅動器上accessable
程序可以運行一個文件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()將是要走的路,除非你需要檢查某些權限? – Tim 2010-10-06 12:50:44
檢查文件/文件夾權限:http://stackoverflow.com/questions/3456397/checking-file-folder-access-permission/3456514 – Rox 2010-10-06 12:52:51