SPSite NDASite = new SPSite(SITE_URL);
SPWeb NDAWeb = NDASite.OpenWeb();
SPList COIList = NDAWeb.Lists[LIST_NAME];
SPListItemCollection listItems = COIList.Items;
SPGroup Group = NDAWeb.SiteGroups["test"];
SPRoleAssignment gr = new SPRoleAssignment(Group);
SPRoleDefinition role = NDAWeb.RoleDefinitions["Contribute"];
gr.RoleDefinitionBindings.Add(role);
//For each item in the list
foreach (SPListItem item in listItems)
{
//Break inheritance
item.BreakRoleInheritance(true);
//Get SPRoleAssignmentCollection
SPRoleAssignmentCollection sr = item.RoleAssignments;
//Removeing all current permissions if needs..
for (int i = 0; i < sr.Count; i++)
{
sr.Remove(i);
}
//Add group to SPRoleAssignmentCollection
sr.Add(gr);
//gr.Update(); - no need to update
}
Monday, February 18, 2008
Subscribe to:
Post Comments (Atom)
2 comments:
Hi,
small mistake in your code
the for next needs to be a minus
for (int i = sr.Count-1;i>-1; i--)
{
sr.Remove(i);
}
Post a Comment