This message was discovered on microsoft.public.dotnet.languages.csharp.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Dan |
I have code like the following to test for existence of a file. I know the file is there, but File.Exists returns FALSE. The problem appears to be that the file is in a directory beneath "My Documents". When I move it to a directory directly under the root, File.Exists returns TRUE. So I tried using FileIOPermission to give me rights to read it, but still no luck. Any suggestions? Thanks...
FileIOPermission f = new FileIOPermission(FileIOPermissionAccess.AllAccess, fileName); if (!File.Exists(fileName)) throw new FileNotFoundException("Unable to construct BinaryUploadFile object. File does not exist:\n\n" + fileName + "\n\n");
|
|
| |
| |
| Nicholas Paldino [.NET/C# MVP] (VIP) |
Dan,
If you don't have access to the directory, then Exists will return false, as you expected.
You are creating the permission to see if you can access the directory, to prevent a false negative. However, you aren't doing anything to indicate whether or not you have permission. Between the call to Exists, and the construction of the permission, call Demand on the permission. It will throw a SecurityException if you don't have access to the directory.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - Click here to reveal e-mail address
"Dan" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
| |
| | |
|
| |
| Willy Denoyette [MVP] (VIP) |
If you (the windows identity running the code) don't have the right permissions to the folder holding the file, File.Exists will return false, as you are experiencing. This is called "windows access security " based on the identity of the caller. You are confusing this security mechanism with .NET's "Code access security" , this kind of security mechanism is based on the "code identity" (where did the code came from - internet, intranet, codegroup , ...) NOT the windows user identity, these are fundamentally different. Whatever you do in code (that is Code Access Security) won't help if the "windows user" has no access rights for the objects (like files) controlled by the OS security system (Windows security).
In short you need to fix the NTFS security settings on the file/folder.
Willy.
"Dan" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
| |
| | |
|
|
|
|
|