In my application I need to search for a network path and do some processing based on the existence of the folder. Let us take an example, I have to search for a path on network and if path exists I have to enable some controls otherwise I need to disable the controls.
I tried using DirectoryInfo object and getting the correct values:
DirectoryInfo dirInfo = new DirectoryInfo(@"\ServerIPAddress\FolderName");
if(dirInfo.Exists)
{
//do something
}
else
{
//do something else
}
The problem with the above code is it is consuming more than 2 minutes for getting the Exists property.
Is there any faster way to check for network path existence.
Thanks and regards,
Ashish Sharma
Usually this would take time only if the folder does not exist in the specified path.
You could use a different thread to check the existence of the folder as described here (along with delegates): How to avoid network stalls in GetFileAttributes?
Also you can check this related question: How To: Prevent Timeout When Inspecting Unavailable Network Share – C#