Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 450
Martin Avatar asked Oct 26 '10 20:10

Martin


3 Answers

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

bool folderExists = Directory.Exists(@"\\Path\To\Folder");
like image 181
Kyle Trauberman Avatar answered Oct 24 '22 17:10

Kyle Trauberman


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.

like image 35
NeilMonday Avatar answered Oct 24 '22 19:10

NeilMonday


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?

like image 45
user207421 Avatar answered Oct 24 '22 19:10

user207421