Directory.Exists issue

  • Thread starter Thread starter Santel
  • Start date Start date
S

Santel

Hi,

If I use Directory.Exists("C://Documents and Settings//username//
Testing); it always returns false. But the directory is existing in
the specified folder. It is not searching any folders under "C://
Documents and Settings//username".

Anyone please suggest what are the possibilities of this issue?
 
Santel said:
Hi,

If I use Directory.Exists("C://Documents and Settings//username//
Testing); it always returns false. But the directory is existing in
the specified folder. It is not searching any folders under "C://
Documents and Settings//username".

Anyone please suggest what are the possibilities of this issue?

Try single slashes instead of double.
 
The slashes are reversed.
Use backslashes instead of forward slashes.

Also, only use double slashes if you're using C#.
If you're using VB.NET, use single slashes.




Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
Hi,

If I use Directory.Exists("C://Documents and Settings//username//
Testing); it always returns false. But the directory is existing in
the specified folder. It is not searching any folders under "C://
Documents and Settings//username".

Anyone please suggest what are the possibilities of this issue?

ASPNET account has no rights to browse that folder.

Go to the Properties of the folder, Security Tab and add ASPNET
account to the list (at least Read rights).
 
The slashes are reversed.
Use backslashes instead of forward slashes.

Also, only use double slashes if you're using C#.
If you're using VB.NET, use single slashes.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================

Actually, forward slashes are just as legit. In fact they can also be
doubled.

The following all evaluate to true:

Console.WriteLine(Directory.Exists("C:\\temp\\temp"));
Console.WriteLine(Directory.Exists("C:/temp/temp"));
Console.WriteLine(Directory.Exists("C://temp//temp"));

The problem could be something else -- perhaps a rights issue
 
Back
Top