Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Using Directory.Exists on a network folder when the network is down
- bool pathExists = Directory.Exists(path);
- Func<bool> func = () => Directory.Exists(path);
- Task<bool> task = new Task<bool>(func);
- task.Start();
- if (task.Wait(100)) {
- return task.Value;
- } else {
- // Didn't get an answer back in time be pessimistic and assume it didn't exist
- return false;
- }
- public static bool DirectoryExists(string path)
- {
- try
- {
- if(System.IO.Directory.GetDirectories(path).Length>0)
- return true;
- }
- catch(Exception exp)
- {
- }
- return false; }
- [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);
- }
- }
- public static bool FolderExists(string directory)
- {
- if (new Uri(directory, UriKind.Absolute).IsUnc && !Connected)
- return false;
- return System.IO.Directory.Exists(directory);
- }
Add Comment
Please, Sign In to add comment