This post originated from an RSS feed registered with .NET Buzz
by David Cumps.
Original Post: Setting NTFS Permissions with C#
Feed Title: David Cumps
Feed URL: http://weblogs.asp.net/cumpsd/rss?containerid=12
Feed Description: A Student .Net Blog :p
Today I needed to set NTFS permissions in C# on some newly created directories.
No problem I thought, the CLR will have something for it somewhere in Security, so I checked Google in the hopes to find which class to use.
But Google didn't find anything... This amazed me. "Why can't I control NTFS permissions with .NET ?!?"
After looking for an hour or so, I found a GotDotNet User Sample, called 'ACLs in .NET'. Finally I thought, now it's going to be plug in and set rights.
Well this library is great. It makes settings NTFS rights so easy.
But it lacks a bit in documentation. Therefore I'm providing some of the code I used with it, it could help you. (or it could show my possibly bad coding style, as far as my knowledge goes for know, it should be fine)
Reference the dll, and use it.
using Microsoft.Win32.Security;
Here's a method to add a dir, and set NTFS permissions on it for a given user: