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

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

Thanks!

+7
c # networking wmi
source share
3 answers

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

 bool folderExists = Directory.Exists(@"\\Path\To\Folder"); 
+5
source share

Perhaps try the Ping class:

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

It will tell you if the host is available, but I donโ€™t know if it will tell you if any specific share / path is available.

+2
source share

Just try using it. This will result in an error if it is not. You should still code this condition: why do it twice?

+1
source share

All Articles