A
Ayende Rahien
<rant warning="I'm pissed off and have to vent" request="need help>
For the last couple of hours I'm struggling with a very *annoying* problem.
How to check if a user has a write access to a file?
Considerring that .Net is supposed to be a system for writing applications
for servers & clients, which in both cases has may have multi-users, I'm
amazed that this is not possible in the framework.
Initially I looked for something like:
System.IO.File.Access(string Filename, PermissionAccess);
Nothing!
Then I thought about System.Security.Permissions, and there is was, clear as
day FileIOPermission a class which "Controls the ability to access files
and folders."
But no! FileIOPermission works for .Net permissions, it doesn't do Win32
permissions!
Considerring that the framework is supposed to run on server class
platforms, why the omission?
In C & C++ I can do _access() and get the info I want, in .Net? I get to
delve into:
A> Interop code.
B> Win32 Security.
I can handle Interop if I absolutely have to, but even on a good day, using
C++ I don't like Win32 Security, and all the tricks that are used there.
I checked ACLs in .Net
http://www.gotdotnet.com/community/...mpleguid=e6098575-dda0-48b8-9abf-e0705af065d9
No go, it requires me to add a component that is bigger then my code just to
do so, and add several level of complexities to my life.
Not to mention, again, having to deal with all the minor details of Win32
security.
To remind you, I'm trying to find out if my code has write access to a file,
on a framework that support multiply users, networks and such, this should
be a snap.
Instead...
Opening a file and catching the exception is the only easy way that I've,
and that is *not acceptable*.
</rant>
Seriously now, I really need a way to solve this problem, preferably with
something like:
FileAccess.Verify(filename,WriteAccess);
Thanks in advance,
Ayende Rahien
For the last couple of hours I'm struggling with a very *annoying* problem.
How to check if a user has a write access to a file?
Considerring that .Net is supposed to be a system for writing applications
for servers & clients, which in both cases has may have multi-users, I'm
amazed that this is not possible in the framework.
Initially I looked for something like:
System.IO.File.Access(string Filename, PermissionAccess);
Nothing!
Then I thought about System.Security.Permissions, and there is was, clear as
day FileIOPermission a class which "Controls the ability to access files
and folders."
But no! FileIOPermission works for .Net permissions, it doesn't do Win32
permissions!
Considerring that the framework is supposed to run on server class
platforms, why the omission?
In C & C++ I can do _access() and get the info I want, in .Net? I get to
delve into:
A> Interop code.
B> Win32 Security.
I can handle Interop if I absolutely have to, but even on a good day, using
C++ I don't like Win32 Security, and all the tricks that are used there.
I checked ACLs in .Net
http://www.gotdotnet.com/community/...mpleguid=e6098575-dda0-48b8-9abf-e0705af065d9
No go, it requires me to add a component that is bigger then my code just to
do so, and add several level of complexities to my life.
Not to mention, again, having to deal with all the minor details of Win32
security.
To remind you, I'm trying to find out if my code has write access to a file,
on a framework that support multiply users, networks and such, this should
be a snap.
Instead...
Opening a file and catching the exception is the only easy way that I've,
and that is *not acceptable*.
</rant>
Seriously now, I really need a way to solve this problem, preferably with
something like:
FileAccess.Verify(filename,WriteAccess);
Thanks in advance,
Ayende Rahien