473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Using Directory.Exists for UNC path is sloowwwwww

css
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?


Dec 22 '05 #1
4 15075
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 )

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

"css" <id************@forgetit.com> wrote in message
news:96**********************************@microsof t.com...
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?

Dec 22 '05 #2
css
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?

Dec 22 '05 #3
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);
}

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

"css" <id************@forgetit.com> wrote in message
news:2F**********************************@microsof t.com...
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?

Dec 23 '05 #4
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.
"css" <id************@forgetit.com> wrote in message
news:96**********************************@microsof t.com...
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?

Dec 24 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
4
by: Elmo Watson | last post by:
Is there a way, with the System.IO class, to do a recursive list of a directory structure? For instance, in DirectoryInfo, you have GetDirectories and GetFiles .... In Directory, you have...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
6
by: Sigmathaar | last post by:
Hi, while making an XML parser for the creation of an entire directory list I got this problem and I'm having trouble solving it. The program (not yet written) goes through an XML Schema Instance...
23
by: **Developer** | last post by:
Is there an easy way to copies all files in a directory into another directory? What about coping subdirectories too? Thanks in advance for any info
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
0
by: nagashree | last post by:
Hi, i want to compress the file or directory i am able to do that can anybody help me to decompress the file when i double click on the zipped file i am getting the error message as...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.