简体   繁体   中英

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

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

Thanks!

您可以使用Directory.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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM