views:

110

answers:

1

Here is the scenario..

===== scanario 1 ===== 1. Document Library "Gatorate Classic" 2. I have four groups. Group Alpha - Role - Read Group Beta - Role - Edit Group Epselon - Role - Edit Group Gamma - Role - Edit

===== scanario 2 ===== 1. Document Library "Gatorate G2" 2. I have four groups. Group Alpha - Role - Edit Group Beta - Role - Read Group Epselon - Role - Edit Group Gamma - Role - Read


I tried to follow this link but http://www.csharpest.net/?p=74 but i dont think this is my solution. Did anyone had a scenario like this. Same group but different level access.

A: 

I Have something where I change the permission level on a Document Library (with Pages) but I have a different need so I built privileges on the pages.

            string groupname = "Group Alpha";
            SPWeb web = getSPWeb();
            web.AllowUnsafeUpdates = true;
            SPGroup grupo = web.Groups[groupname];
            SPFile arq = null;
            SPFolder pasta = web.GetFolder("pages");
            arq = pasta.Files["page1.aspx"];

            if (arq.InDocumentLibrary)
            {
                SPListItem item = arq.Item;
                if (!item.HasUniqueRoleAssignments)
                    item.BreakRoleInheritance(false);
                SPRoleAssignmentCollection roles = item.RoleAssignments;
                while (roles.Count > 0)
                    roles.Remove(0);

                SPRoleAssignment atrib1 = new SPRoleAssignment(web.Groups[groupname] as SPPrincipal);
                atrib1.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Administrator));
                roles.Add(atrib1);

            }
            web.AllowUnsafeUpdates = false;

Hopes this helps you.

Gabriel Guimarães
Thanks Gabriel, I can certainly your code. Thanks Again
I kept getting following error. This operation is not allowed on an object that inherits permissions.I added this line and now the error is gone and group is added for the document library in question with whatever role I added.webSite.BreakRoleInheritance(true);Thanks Gabi...
You probably should only break the Role Inheritance in the Library you need, you can check if the Role Inheritance is already broken by checking the HasUniqueRoleAssignments boolean property. And if you break the Role Inheritance passing true it will copy the privileges that were already there, if you desire no privileges on the copied object you should pass false.
Gabriel Guimarães