Ping UNC path
The code Directory.Exists(“uncPath”); is too slow for unavailable/disconnected unc path. So, to solve this issue, we can ping the unc path before checking for the directory. The following code snippet will give you an idea of pinging unc path,
public static bool PingUNCPath(string uncPath)
string hostNameOrAddress = string.Empty;
string uncPathMembers = uncPath.Split(‘\\’);
//You may have a path some thing like \\\\abcd001\\Documents\\New\\
//We need only the computer name. So split the path.
//Get the host name or address.
foreach (string pathName in uncPathMembers)
//first non empty word is host name
hostNameOrAddress = pathName;
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply reply = ping.Send (hostNameOrAddress, 200); //200ms
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
catch //if host name is not found, you get ping exception!!!
//object disposed exception
No comments yet.