473,320 Members | 1,922 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,320 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 20078
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.