473,401 Members | 2,146 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,401 software developers and data experts.

File.Exists question

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");
Nov 16 '05 #1
18 3135
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]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");

Nov 16 '05 #2
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]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");

Nov 16 '05 #3
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" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");

Nov 16 '05 #4
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" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");

Nov 16 '05 #5
Dan
Thanks Nick, but it didn't seem to work. Changed the code to this (see
below), but Exists still returned false. Any more ideas?

FileIOPermission f = new
FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
f.Demand();
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]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");


Nov 16 '05 #6
Dan
Thanks Nick, but it didn't seem to work. Changed the code to this (see
below), but Exists still returned false. Any more ideas?

FileIOPermission f = new
FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
f.Demand();
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]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");


Nov 16 '05 #7
Dan
But I'm running with administrative rights, with full access to the files in
that directory. Could it have something to do with running from the
debugger?

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
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" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");


Nov 16 '05 #8
Dan
But I'm running with administrative rights, with full access to the files in
that directory. Could it have something to do with running from the
debugger?

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
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" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");


Nov 16 '05 #9
Dan,

Just a question, what is the value being passed in for fileName, and the
actual path to the filename you are trying to find?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:uh**************@TK2MSFTNGP09.phx.gbl...
Thanks Nick, but it didn't seem to work. Changed the code to this (see
below), but Exists still returned false. Any more ideas?

FileIOPermission f = new
FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
f.Demand();
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]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
>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");
>
>



Nov 16 '05 #10
Dan,

Just a question, what is the value being passed in for fileName, and the
actual path to the filename you are trying to find?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:uh**************@TK2MSFTNGP09.phx.gbl...
Thanks Nick, but it didn't seem to work. Changed the code to this (see
below), but Exists still returned false. Any more ideas?

FileIOPermission f = new
FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
f.Demand();
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]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
>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");
>
>



Nov 16 '05 #11
Dan,

It could be that you simply don't have the NTFS permissions (which the
permissions class is not going to pick up), and File.Exists is going to
return false. The Exists method actuall uses the FindFirstFile API function
to determine if the file exists, and I imagine that if the user account the
app is running under doesn't have rights to that directory, then it will
return false to see if it exists.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:uh**************@TK2MSFTNGP09.phx.gbl...
Thanks Nick, but it didn't seem to work. Changed the code to this (see
below), but Exists still returned false. Any more ideas?

FileIOPermission f = new
FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
f.Demand();
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]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
>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");
>
>



Nov 16 '05 #12
Dan,

It could be that you simply don't have the NTFS permissions (which the
permissions class is not going to pick up), and File.Exists is going to
return false. The Exists method actuall uses the FindFirstFile API function
to determine if the file exists, and I imagine that if the user account the
app is running under doesn't have rights to that directory, then it will
return false to see if it exists.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:uh**************@TK2MSFTNGP09.phx.gbl...
Thanks Nick, but it didn't seem to work. Changed the code to this (see
below), but Exists still returned false. Any more ideas?

FileIOPermission f = new
FileIOPermission(FileIOPermissionAccess.AllAccess, fileName);
f.Demand();
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]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Dan" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
>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");
>
>



Nov 16 '05 #13
Are you completely sure the file name is correct?
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Dan" <da*@dontspamme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
But I'm running with administrative rights, with full access to the files in that directory. Could it have something to do with running from the
debugger?

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
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" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");



Nov 16 '05 #14
Are you completely sure the file name is correct?
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Dan" <da*@dontspamme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
But I'm running with administrative rights, with full access to the files in that directory. Could it have something to do with running from the
debugger?

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:OW**************@TK2MSFTNGP14.phx.gbl...
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" <da*@dontspamme.com> wrote in message
news:Os**************@TK2MSFTNGP15.phx.gbl...
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");



Nov 16 '05 #15
Ok, make sure the file path is correct and/or check if the administrators
group has access to the folder.

Willy.

"Dan" <da*@dontspamme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
But I'm running with administrative rights, with full access to the files
in
that directory. Could it have something to do with running from the
debugger?

Nov 16 '05 #16
Ok, make sure the file path is correct and/or check if the administrators
group has access to the folder.

Willy.

"Dan" <da*@dontspamme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
But I'm running with administrative rights, with full access to the files
in
that directory. Could it have something to do with running from the
debugger?

Nov 16 '05 #17
Dan
Sorry to waste your time. I was pulling the filename out some XML which was
generated on another machine; thus the "My Documents" paths were different.
While I'm at it, is an assembly directive like the one below the best way to
ensure you have file access rights on an assembly-wide basis:

[assembly:PermissionSetAttribute(SecurityAction.Req uestMinimum, Name =
"FullTrust")]
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:u7**************@TK2MSFTNGP11.phx.gbl...
Ok, make sure the file path is correct and/or check if the administrators
group has access to the folder.

Willy.

"Dan" <da*@dontspamme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
But I'm running with administrative rights, with full access to the files in
that directory. Could it have something to do with running from the
debugger?



Nov 16 '05 #18
Dan
Sorry to waste your time. I was pulling the filename out some XML which was
generated on another machine; thus the "My Documents" paths were different.
While I'm at it, is an assembly directive like the one below the best way to
ensure you have file access rights on an assembly-wide basis:

[assembly:PermissionSetAttribute(SecurityAction.Req uestMinimum, Name =
"FullTrust")]
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:u7**************@TK2MSFTNGP11.phx.gbl...
Ok, make sure the file path is correct and/or check if the administrators
group has access to the folder.

Willy.

"Dan" <da*@dontspamme.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
But I'm running with administrative rights, with full access to the files in
that directory. Could it have something to do with running from the
debugger?



Nov 16 '05 #19

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

Similar topics

10
by: Raymond | last post by:
Hi All: To find a file exists using the file name, I have tow routings on UNIX system. 1. access(2) 2. lstat(2) This tow function also can do. When the return value is "-1" and errno is...
2
by: Chris Fink | last post by:
I am using the System.IO.File class to determine if a file exists on a network share. The File.Exists method keeps returning false, even though the file does exist. The MSDN documentation...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
3
by: Lou | last post by:
Question: I can't seem to get file.exists(filename) to return true when I search using wildcards, and I know there's a file in that dir with that extension. here's the path dim yesno as...
1
by: Tim Failes | last post by:
This seems a trival question, but I cannot get it to work properly... Essentially my question is, how can I create a text file, and guarantee it is given the current date/time as the Creation Time?...
52
by: paytam | last post by:
Hi all Can anyone tell me how can I check that a file exist or no.I mean when you use this commands FILE *fp; if(!fp) //Could not open the file doen't show why it can not open it,may be the...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
7
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not...
8
by: Sweetiecakes | last post by:
In our series of "probably something simple"... I am doing a File.Exists operation to check if a file exists. Let's assume that this file is C:/test.txt. Now, if I do...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.