我有一个C#进程需要读取远程服务器上共享目录中存在的文件.
以下代码导致“共享不存在”.被写入控制台.
string fileName = "someFile.ars"; string fileLocation = @"\\computerName\share\"; if (Directory.Exists(fileLocation)) { Console.WriteLine("Share exists."); } else { Console.WriteLine("Share does not exist."); }
该过程在AD用户帐户下运行,同一帐户被授予共享目录的完全控制权限.我可以成功将共享映射为进程所在机器上的网络驱动器,并可以将文件复制到目录或从目录复制文件.关于我缺少的任何想法?
解决方法
使用File.Exists而不是Directory.Exists.
另外,您可能希望在某种程度上与平台无关,并使用规范的Path.Combine:
string fileName = "someFile.ars"; string fileServer = @"\\computerName"; string fileLocation = @"share"; if (File.Exists(Path.Combine(fileServer,fileLocation,fileName))) { Console.WriteLine("Share exists."); } else { Console.WriteLine("Share does not exist."); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。