开发者

How to determine if a network path is available or not (online or offline)?

开发者 https://www.devze.com 2023-01-21 21:49 出处:网络
Using .NET / C#, how to determine if a network 开发者_JAVA百科path (e.g. \\mymachine\\myfolder) is available or not (online or offline)? Is there a way to be notified by WMI of such event?

Using .NET / C#, how to determine if a network 开发者_JAVA百科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!


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

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


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消