Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / December 2005

Tip: Looking for answers? Try searching our database.

Using Directory.Exists for UNC path is sloowwwwww

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
css - 22 Dec 2005 15:59 GMT
When I call Directory.Exists for a UNC path like below...

    if (Directory.Exists(@\\SomeServer\C) == false)
    {
       ....
    }

and that server does not exist on the connected network, it takes around a
minute to return from the call which properly returns false.

Is there a faster way to determine if a directory or server exists on the
network?


Vadym Stetsyak - 22 Dec 2005 16:26 GMT
When you try to access remote server, network redirector tries to get the
address of the server. It issues DNS query. This process takes a while...

AFAIK there can be several solutions:
- if you know the IP address of the server, try to connect to it on 135-139
( for UNC )
- if you know the IP substitue it into the UNC path.
- if you do not know the IP try to resolve it manually using Dns.Resolve (
.NET 1.0 - 1.1 )
 or GetHostEntry ( .NET 2.0 )

Signature

Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

> When I call Directory.Exists for a UNC path like below...
>
[quoted text clipped - 8 lines]
> Is there a faster way to determine if a directory or server exists on the
> network?
css - 22 Dec 2005 19:58 GMT
Vadym,

I don't know the IP.  If I use or GetHostEntry() it resolves to a name
without throwing an exception even if the server doesn't exist! If I put

a legit name like:

GetHostEntry("\\MyLocalMachineName")

it returns "MyLocalMachineName.hilton.com" but the IP is 0.0.0.1.  (Which is
incorrect I am using a wirless connection at the Hilton hotel and the DHCP
address is 10.252.1.100).

If I use an illegit name, like
GetHostEntry("\\VADYM")

it returns "VADYM.hilton.com" and the IP is also 0.0.0.1.  

Am I missing something?
Vadym Stetsyak - 23 Dec 2005 11:30 GMT
GetHostEntry returns the list of ips, did you check the whole list?
smth like

IPHostEntry host;
host = Dns.GetHostEntry(hostname);

Console.WriteLine("GetHostEntry({0}) returns:", hostname);

foreach (IPAddress ip in host.AddressList)
{
   Console.WriteLine("    {0}", ip);
}

Signature

Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

> Vadym,
>
[quoted text clipped - 16 lines]
>
> Am I missing something?
Willy Denoyette [MVP] - 24 Dec 2005 18:48 GMT
Why are you trying this for a path (server) that doesn't exists in the first
place? Why not ping the server before trying to connect to a remote share
exposed by the server?

Willy.

> When I call Directory.Exists for a UNC path like below...
>
[quoted text clipped - 8 lines]
> Is there a faster way to determine if a directory or server exists on the
> network?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.