3

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

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Ashish Sharma
  • 357
  • 2
  • 5
  • 16
  • 1
    You mean `@"\\ServerIPAddress\FolderName"` (two backslash)? – Miserable Variable Nov 01 '11 at 06:41
  • possible duplicate of [How to avoid network stalls in GetFileAttributes?](http://stackoverflow.com/questions/1142080/how-to-avoid-network-stalls-in-getfileattributes) – jgauffin Nov 01 '11 at 07:28
  • possible duplicate of http://stackoverflow.com/questions/726602/how-to-prevent-timeout-when-inspecting-unavailable-network-share-c-sharp – jgauffin Nov 01 '11 at 07:29

1 Answers1

2

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#

Community
  • 1
  • 1
Kash
  • 8,799
  • 4
  • 29
  • 48
  • That was the first thing I tried. Don't have that privilege yet :( – Kash Nov 01 '11 at 21:55
  • Thanks for the approach. I am right now using the approach specified by you. For the time being problem is resolved but I may require to find a new way soon! – Ashish Sharma Nov 20 '11 at 04:57