如何判断网络路径是否可用(在线或离线)?

发布于 2024-09-29 14:43:14 字数 92 浏览 3 评论 0原文

使用.NET / C#,如何确定网络路径(例如\mymachine\myfolder)是否可用(在线或离线)?有没有办法让 WMI 通知此类事件?

谢谢!

Using .NET / C#, how to determine if a network path (e.g. \mymachine\myfolder) is available or not (online or offline)? Is there a way to be notified by WMI of such event?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

昔日梦未散 2024-10-06 14:43:14

您可以使用Directory.Exists来检查路径是否存在。

bool folderExists = Directory.Exists(@"\\Path\To\Folder");

You can use Directory.Exists to check if a path exists.

bool folderExists = Directory.Exists(@"\\Path\To\Folder");
dawn曙光 2024-10-06 14:43:14

也许尝试 Ping 类:

http://msdn.microsoft .com/en-us/library/system.net.networkinformation.ping.aspx

它会告诉你主机是否可用,但我不知道它是否会告诉你特定的共享/路径是否可用可用的。

Maybe try the Ping class:

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx

It will tell you if a host is available, but I don't know if it will tell you whether a particular share/path is available.

残花月 2024-10-06 14:43:14

尝试使用它。如果不是,则会导致错误情况。无论如何,你都必须针对这种情况进行编码:为什么要这样做两次?

Just try to use it. It will cause an error condition if it isn't. You have to code against that condition anyway: why do it twice?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文