 |

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...
|
|

12-07-2006, 08:06 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
What permissions do you have on the machine? Are you an Admin? Are you in the "VS Developers", or "Debugger Users" Groups?
I'm just grasping at straws because I've never had a problem with anything on C.
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

12-08-2006, 03:40 AM
|
|
Freshman
|
|
Join Date: May 2003
Location: London, UK
Posts: 36
|
|
|
I am in the following groups:
Debugger Users
Administrators
Power Users
I switched 'Debugger Users' with 'VS Developers' and re-logged-on; however, that didn't make any difference. I don't seem to be able to assign myself to both the 'Debugger Users' AND 'VS Developers', because it only allows one selection (I am changing my groups via Control Panel | User Accounts | Users tab | Properties | Group Membership tab, which provides a dropdown list to select 'Other' type of user. I'm using Windows XP if that makes a difference).
However, interestingly, the user account for a contractor we employed a while ago is assigned to 'Administrators', 'Debugger Users' and 'VS Developers'. I may be being stupid, but I can't see how this selection can be made via the above interface...
|
|

12-08-2006, 08:15 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
you shouldn't need to be in all of them. But you can get in multiple groups by going into Computer Management, and selecting Local Users and Groups.
(Right click on "My Computer" and go to Manage.)
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

12-08-2006, 08:26 AM
|
|
Freshman
|
|
Join Date: May 2003
Location: London, UK
Posts: 36
|
|
|
Thanks, I've done that, but as (I think) you implied, it doesn't solve the problem...
When I am stepping through the code in debug mode, does it / should it automatically run under my user account? If so, how would I check this?
|
|

12-08-2006, 08:35 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
yes. stepping through code will run with your permissions. unless you're doing some explict Impersonation, but you'd know if that's the case.
If you go into .NET Configuration under administration tools, can you check to see what the trust level is for your computer?
Click on: Configure Code Access Security Policy
Click on: Adjust Zone Security
Select: Make Changes to this Computer, Click Next
Check: "My Computer"
Make sure it is Full Trust.
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

12-08-2006, 08:42 AM
|
|
Freshman
|
|
Join Date: May 2003
Location: London, UK
Posts: 36
|
|
|

12-08-2006, 08:48 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
Instead of "Make Changes to this Computer", select "Make Changes for the Current User".
Does that have Full Trust as well?
If so, I'm afraid I've run out of things to check... Do you have all of the Famework Service Packs installed?
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

12-08-2006, 08:52 AM
|
|
Freshman
|
|
Join Date: May 2003
Location: London, UK
Posts: 36
|
|
Ah-ha! That was set to one level below Full Trust. I've changed it to Full Trust and everything is now working as it should
Many thanks for all your help Wayne.
|
|

12-08-2006, 08:56 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
Good. Because I ran out of other things to look at.
Glad it's working now. 
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear 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
|
|
|
|
|
|