 |
 |

12-06-2006, 11:45 AM
|
|
Freshman
|
|
Join Date: May 2003
Location: London, UK
Posts: 36
|
|
Directory.Exists always returns false
|
Hi
I am trying to check whether a directory exists, by using the following code:
Code:
Dim bResult As Boolean = Directory.Exists("c:\temp")
MsgBox(bResult)
However, it always returns False even when the directory definitely does exist.
I've had a search around, and I'm thinking it may be something to do with security settings (although it doesn't throw any kind of exception).
Can anyone help please?
Thanks
Wendy
|
|

12-06-2006, 11:51 AM
|
 |
Keeper of foo
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
|
|
__________________
~ Quod non mortiferum, fortiorem me facit ~
Avatar by lebb
|

12-06-2006, 12:16 PM
|
|
Freshman
|
|
Join Date: May 2003
Location: London, UK
Posts: 36
|
|
Hmm, definitely doesn't for me...
I've done some more investigation, and it seems that Directory.Exists may not actually be looking at my c drive at all. If I get a file listing as follows:
Code:
Dim str As String
Dim FileList() As String
FileList = Directory.GetFiles("c:", "*")
For i As Integer = 0 To FileList.Length - 1
str &= FileList(i) & Chr(13)
Next i
MsgBox(str)
...the msgbox returns:
MyProject.exe
MyProject.exe.config
MyProject.pdbc
So, it's doesn't actually seem to be looking at my c: drive at all, but at the project directory.... Directory.Exists("c:") also returns True.
If I use the same code as above, but get it to search in "c:\" (i.e. with a backslash), it raises a security exception:
An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll
"Additional information: Request for the permission of type System.Security.Permissions.FileIOPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed."
Any ideas?
Thanks
Wendy
|
|

12-07-2006, 06:59 AM
|
|
Freshman
|
|
Join Date: May 2003
Location: London, UK
Posts: 36
|
|
I got some help on this from a colleague, so thought I would post the solution we found. The problem *was* to do with my security settings, and the following steps fixed it:
1. Go to Control Panel | Administrative Tools | Microsoft .NET Framework 1.1 Wizards
2. Click 'Trust an Assembly'
3. Next
4. Add the exe file as a 'manged assembly to trust'
4. Next
5. Selected 'Full Trust'
Directory.Exists then returns the correct result
The only problem with the above is that the exe needs to be re-trusted each time it's compiled, so if anyone has any ideas about how to always trust projects that I create, I'd be interested to hear them.
Thanks
Wendy
|
Last edited by wensly; 12-07-2006 at 07:05 AM.
|

12-07-2006, 07:33 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
Are you creating it on your C:\ drive or is it running from a network location or something like that? I've never had a problem with locally created apps. On the Network, I have set up a Trusted location so that I can create apps in a location that is backed up, and don't run into the Security Exceptions.
Any more information you can provide about your development environment would be appreciated.
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

12-07-2006, 07:41 AM
|
|
Freshman
|
|
Join Date: May 2003
Location: London, UK
Posts: 36
|
|
|
Hi, thanks for your reply.
It's on my local drive in a directory called c:\Projects\MyProjectName, and it gets checked into Source Safe at the end of every day. I know that if I try to save a project to a network location, it tells me that it's not trusted, but this does not happen when I save to c:\Projects.
To be honest, I don't have a clue about permissions / security, so I'm not sure what other options / settings I might need to look at...
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|