By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 2,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Check for "Write Access" on a file/folder in .NET

P: n/a
Hello All,
Our application write logs to a file in a folder. Before our application
starts writing to that file, I want to check if the current user has write
access to that file, for example, "c:\temp\LogFile.txt".
I see several articles for setting file access permissions, getting file
access permissions for a given user or current user - but the current user
could also gain write access to the same file not just by explicit permssion
but also thru implicit permissions. for example, the current user may be in
a NT group which can have write access to that file - so this user also gets
write access.
How to check if the current user can have write access either thru explicit
or implcit permssions set on the folder/file?.

All the following articles below talk about retrieving explicit permssions
or setting permissions but nothing talks about checking if the user has
access to that file thru implicit permssions.
In short, I want to check if the current user has write access to the file
"c:\temp\LogFile.txt".

Can someone help?

File.GetAccessControl Method
http://msdn2.microsoft.com/en-us/lib...sscontrol.aspx

FileSecurity Class
http://msdn2.microsoft.com/en-us/lib...esecurity.aspx

FileSecurity Members
http://msdn2.microsoft.com/en-us/lib...y_members.aspx
Jan 3 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Open the file for 'write' access, with the statement wrapped in a try catch.

If the statement succeeds then the user has 'write' access.

If the statement throws an exception then inspect the exception to determine
the reason.
"Ganesh Muthuvelu" <Ga*************@discussions.microsoft.comwrote in
message news:47**********************************@microsof t.com...
Hello All,
Our application write logs to a file in a folder. Before our application
starts writing to that file, I want to check if the current user has write
access to that file, for example, "c:\temp\LogFile.txt".
I see several articles for setting file access permissions, getting file
access permissions for a given user or current user - but the current user
could also gain write access to the same file not just by explicit
permssion
but also thru implicit permissions. for example, the current user may be
in
a NT group which can have write access to that file - so this user also
gets
write access.
How to check if the current user can have write access either thru
explicit
or implcit permssions set on the folder/file?.

All the following articles below talk about retrieving explicit permssions
or setting permissions but nothing talks about checking if the user has
access to that file thru implicit permssions.
In short, I want to check if the current user has write access to the file
"c:\temp\LogFile.txt".

Can someone help?

File.GetAccessControl Method
http://msdn2.microsoft.com/en-us/lib...sscontrol.aspx

FileSecurity Class
http://msdn2.microsoft.com/en-us/lib...esecurity.aspx

FileSecurity Members
http://msdn2.microsoft.com/en-us/lib...y_members.aspx

Jan 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.