472,791 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

Programmatically check directory permissions

Does anyone know if there is a way to check the access
permissions of different users using C#? I need to know
if a user has full control or if they have read only
access or none to a certain directory. I have seen
different ways to set the permissions but none to read
them. Any help would be appreciated. Thanks in advance.
Nov 16 '05 #1
4 20025
Well, honestly, the easiest way is to try to examine the contents of the
directory. If that works, create a temp file in the directory and delete
it. If you can do all three, you have full control. If you cannot create
the file, but you can read the contents, you have read access. If you
cannot read the directory, you have no access.

Just make sure to catch the exceptions and handle them appropriately.

I suppose you could inspect the ACLs on the directory itself, but it would
be harder than doing the things above.

--- Nick

"Steven" <wh**************@hotmail.com> wrote in message
news:1b*****************************@phx.gbl...
Does anyone know if there is a way to check the access
permissions of different users using C#? I need to know
if a user has full control or if they have read only
access or none to a certain directory. I have seen
different ways to set the permissions but none to read
them. Any help would be appreciated. Thanks in advance.

Nov 16 '05 #2
Thanks for your help Nick. I have been checking the directory
permissions using the example that you provided. Do you know if there is
a way to programatically check the ACLS or if the .NET framework
provides any classes to check the ACLS?

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Thanks for your help Nick. I have been checking the
directory
permissions using the example that you provided. Do you
know if there is
a way to programmatically check the ACLS or if the .NET
framework
provides any classes to check the ACLS?
-----Original Message-----
Well, honestly, the easiest way is to try to examine the contents of thedirectory. If that works, create a temp file in the directory and deleteit. If you can do all three, you have full control. If you cannot createthe file, but you can read the contents, you have read access. If youcannot read the directory, you have no access.

Just make sure to catch the exceptions and handle them appropriately.
I suppose you could inspect the ACLs on the directory itself, but it wouldbe harder than doing the things above.

--- Nick

"Steven" <wh**************@hotmail.com> wrote in message
news:1b*****************************@phx.gbl...
Does anyone know if there is a way to check the access
permissions of different users using C#? I need to know
if a user has full control or if they have read only
access or none to a certain directory. I have seen
different ways to set the permissions but none to read
them. Any help would be appreciated. Thanks in advance.

.

Nov 16 '05 #4
Yes, Renaud Paguay has done all the P/Invoke work in a GotDotNet user
sample:

http://www.gotdotnet.com/Community/U...f-e0705af065d9

HTH,

--
Scott
http://www.OdeToCode.com

On Sat, 12 Jun 2004 23:09:52 -0700,
<an*******@discussions.microsoft.com> wrote:
Thanks for your help Nick. I have been checking the
directory
permissions using the example that you provided. Do you
know if there is
a way to programmatically check the ACLS or if the .NET
framework
provides any classes to check the ACLS?
-----Original Message-----
Well, honestly, the easiest way is to try to examine the

contents of the
directory. If that works, create a temp file in the

directory and delete
it. If you can do all three, you have full control. If

you cannot create
the file, but you can read the contents, you have read

access. If you
cannot read the directory, you have no access.

Just make sure to catch the exceptions and handle them

appropriately.

I suppose you could inspect the ACLs on the directory

itself, but it would
be harder than doing the things above.

--- Nick

"Steven" <wh**************@hotmail.com> wrote in message
news:1b*****************************@phx.gbl.. .
Does anyone know if there is a way to check the access
permissions of different users using C#? I need to know
if a user has full control or if they have read only
access or none to a certain directory. I have seen
different ways to set the permissions but none to read
them. Any help would be appreciated. Thanks in advance.

.


Nov 16 '05 #5

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

Similar topics

0
by: Tracy Tripp | last post by:
I'm working on a program that takes files by path and moves them into new locations, and then back again if the user intends. Everything is great so far except I cannot figure out how to keep...
13
by: Alexandra | last post by:
Hi, I have a hidden system file that I need to read. I am logged in as an administrator. I can not change the file attributes using the windows explorer.
3
by: James Coleman | last post by:
Hello, The following error is appearing when attempting to create a directory using the availale system.io methods: System.IO.DirectoryNotFoundException: Could not find a part of the path...
2
by: Buddy Robbins | last post by:
Hey folks, I am in desparate need of help to solve my problem. I have written a service that examines a table in a database, and creates a directory hierarchy based on data in the table. It...
2
by: steggun | last post by:
Hello, I'm writing a C# windows form application and need some guidance on a couple of issues. First, my application needs to change the permissions on a folder. The application creates a...
0
by: thef150 | last post by:
Hello everyone, I am working with the Active Directory Membership provider currently and would like to set connectionUsername and connectionPassword programmatically rather than in the...
6
by: Fred W. | last post by:
When my application starts I need to check folder permissions to ensure they have "Full Control" before I let them proceed on. How can I check this permission. Thank you, Fred
8
by: Chandra | last post by:
How do I programmatically (javascript) check if link is valid in html?
3
by: gareth | last post by:
Hi, Does anyone know of a way of finding out if the currently logged in user has read access to a directory without trying to open the directory?? Thanks gareth
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.