将 DirectoryInfo 与 UNC 路径结合使用
我尝试使用 DirectoryInfo 验证 UNC 路径是否存在,但是当我可以在 Windows 资源管理器中确认该文件夹存在时,DirectoryInfo 一致性会失败并表示该文件夹不存在。
示例
var storagepath = new DirectoryInfo(@"\\123.123.123.123\c$\testfolder\test1\");
if (storagepath.Exists)
{ }
有办法解决这个问题吗?
I'm trying to DirectoryInfo to verify whether a UNC path exists, however DirectoryInfo consistency fails over and says the folder doesn't exist, when I can confirm it does in Windows Explorer.
Example
var storagepath = new DirectoryInfo(@"\\123.123.123.123\c$\testfolder\test1\");
if (storagepath.Exists)
{ }
Is there a way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几个与您的计划有关的问题需要回答。
它是否与您使用资源管理器验证的用户在相同的上下文中运行?例如,您是否有可能以受限用户身份运行控制台应用程序,但以更高权限用户身份登录等?
Exists 为 false 的原因之一包括没有访问该资源的权限。
您可以尝试另一种方法,例如 EnumerateDirectories 并查看结果是什么。 EnumerateDirectories 的异常和结果比 Exists 更具描述性。
There are a few questions that need to be answered in regards to your program.
Is it running in the same context as the user that you're verifying with explorer? Is it possible you are, for example, running a console application as a restricted user but logged in as a higher privilege user, etc?
One of the reasons for Exists being false includes not having permission to access the resource.
You could try another method like EnumerateDirectories and see what the result is. The exceptions and results of EnumerateDirectories are a bit more descriptive than Exists.