views:

263

answers:

2

Hello, I wrote code to set permission of the folder. Function I developed was

public void SetPermission(string user,FileSystemRights rights)
{
    DirectoryInfo dInfo = new DirectoryInfo(folderPath);
    DirectorySecurity oDirectorySecurity = new DirectorySecurity();

    oDirectorySecurity.AddAccessRule(new FileSystemAccessRule(user, rights, AccessControlType.Allow));
    dInfo.SetAccessControl(oDirectorySecurity);
}

This function is working fine to set permission for the user. But when I check folder Properties -> Security , user added. But no permission is checked in checkbox Open Advanced dialogbox. In this box I can see permission , which i set for the user.

So my question is Why there is no checkbox seleced on security tab, but it is there in advanced tab?

Please HELP me!!!!!!

A: 

It might help to use dInfo.GetAccessControl to initialize oDirectorySecurity. You could also try calling oDirectorySecurity.SetOwner.

Sometimes permissions only show up in advanced if they are not applied to to correct objects. Try setting the Inheritance/Propigation flags on your FileSystemAccessRule object.

thealliedhacker
+1  A: 

I ran into this as well. It seems to be a Service Patch thing.

You can read how I fixed it at http://www.jerryandcheryl.net/jspot/2009/01/c-filedirectory-permissions.html

The short version: You have to set a flag for all of the ACLs for all users. Yes... it's ugly. And when you add Service Pack 3, the checkmarks go away again. If anyone has a cleaner solution than this, PLEASE let me know.

I have code for that on my site.

Jerry