I need to create a site with broken permission inheritance. Then I need to create a Members group with contribute access and add people to it.
The following code adds the group to the site collection level, and it also adds the people, but my subsite groups are empty. http://screencast.com/t/T6tFVTu9XHm
What am I missing here?
private static void SetSecurityOnSubSite(ClientContext clientContext, ListItem item, bool confidential, Web newWeb)
{
if (confidential)
{
newWeb.BreakRoleInheritance(false, false);
clientContext.ExecuteQuery();
//Create members group
GroupCreationInformation grpMembers = new GroupCreationInformation();
grpMembers.Title = newWeb.Title + " Members";
Group newMembersGroup = clientContext.Web.SiteGroups.Add(grpMembers);
clientContext.ExecuteQuery();
//Add contribute permission level to members group
RoleDefinition rd = clientContext.Web.RoleDefinitions.GetByName("Contribute");
RoleDefinitionBindingCollection rdb = new RoleDefinitionBindingCollection(clientContext);
rdb.Add(rd);
clientContext.Web.RoleAssignments.Add(newMembersGroup, rdb);
clientContext.ExecuteQuery();
foreach (FieldUserValue userValue in item[Constants.Projects.ProjectTeam] as FieldUserValue[])
{
User user = clientContext.Web.EnsureUser(userValue.LookupValue);
clientContext.Load(user);
clientContext.ExecuteQuery();
UserCreationInformation userCI = new UserCreationInformation();
userCI.LoginName = user.LoginName;
newMembersGroup.Users.Add(userCI);
}
clientContext.ExecuteQuery();
}
}