File Permissions
-
Hi all, I would like to be able to determine at the start of my app if the user has enough permissions for many different files/folders. I have read articles that discuss calling Win32 API NTFS calls, and Active Directory calls to get ACLs, but this seems like something that I would think would be inside dot net some how. No? Like something like: if( File.GetPermissions( "C:\\my cars" ) == FileAccess.Read | FileAccess.Write ) { // good } else { MessageBox.Show( "Not enough permissions. ); } Anyone got any ideas? Thanks alot for any help you can lend, Kris.
-
Hi all, I would like to be able to determine at the start of my app if the user has enough permissions for many different files/folders. I have read articles that discuss calling Win32 API NTFS calls, and Active Directory calls to get ACLs, but this seems like something that I would think would be inside dot net some how. No? Like something like: if( File.GetPermissions( "C:\\my cars" ) == FileAccess.Read | FileAccess.Write ) { // good } else { MessageBox.Show( "Not enough permissions. ); } Anyone got any ideas? Thanks alot for any help you can lend, Kris.
-
Krisp, I do not know if this going to help you or not. But System.IO.File.GetAttributes(FileName)returns a file's attributes. Typical Attributes are Archive, ReadOnly and hidden, I am sure there is more. Hope this helps!
-
No, that doesn't get any file permissions such as: can the user read/write. I had looked at that myself as well. But thanks anyways.
Thats ok, I was reading this on an other site. It deals with permissions. http://www.codeguru.com/cs\_misc/Security.html
-
Hi all, I would like to be able to determine at the start of my app if the user has enough permissions for many different files/folders. I have read articles that discuss calling Win32 API NTFS calls, and Active Directory calls to get ACLs, but this seems like something that I would think would be inside dot net some how. No? Like something like: if( File.GetPermissions( "C:\\my cars" ) == FileAccess.Read | FileAccess.Write ) { // good } else { MessageBox.Show( "Not enough permissions. ); } Anyone got any ideas? Thanks alot for any help you can lend, Kris.
No, there is currently nothing in the .NET base class library that deals with NTFS permissions. There may be some third-party libraries out there and I'm sure "Longhorn" will introduce such encapsulation, but you either have to use the NTFS APIs or try to write a zero-byte file to the directory and catch any exceptions that are thrown. For more discussion about alternatives, please click the "Search Comments" link above. We have covered this in the past. There are also a few articles here on the CP web site. Use the search text box toward the top of the page (below the logo).
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----