| re: C# Programmatically Setting Permissions and Compressing a Folder (NTFS)
"steggun" <nospam@company.comwrote in message
news:%23dWKg2SpGHA.2360@TK2MSFTNGP05.phx.gbl...
| 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 local group and I need to give that group Full
Control
| permissions to a folder on the file system. Would anyone know how to
| accomplish this?
|
| Next, my application also needs to programmatically set the properties of
a
| folder so that it's compressed. Would anyone know how to accomplish this?
|
| Thanks!
|
|
|
When using V2 of the FCL you can use the FileSecurity class in the
System.Security.AccessControl namespace to change the access rights of a
filesystem object. The "compressed" FileAttribute of the DirectoryInfo class
can be used to set the compressed attribute of a folder. However, be aware
that you need to run as an administrator to be able to do this, which is a
bad idea, user applications should never run with administrative privileges.
Much better is to delegate this to an "administrative" application that
could be run as a COM+ server type application (check the
System.EnterpriseServices namespace), this application can run as
administrator while yours keep running with restricted privileges.
Willy. |