My company\'s code base contains the following C# line:
bool pathExists = Directory.Exists(path);
At runtime, the string path
happ
If general network connectivity is your primary problem, you could try testing the network connectivity prior to this:
[DllImport("WININET", CharSet = CharSet.Auto)]
static extern bool InternetGetConnectedState(ref int lpdwFlags, int dwReserved);
public static bool Connected
{
get
{
int flags = 0;
return InternetGetConnectedState(ref flags, 0);
}
}
Then determine if the path is a UNC path and return false if the network is offline:
public static bool FolderExists(string directory)
{
if (new Uri(directory, UriKind.Absolute).IsUnc && !Connected)
return false;
return System.IO.Directory.Exists(directory);
}
None of this helps when the host you're trying to connect to is offline. In that case you're still in for 2-minute network timeout.