I have created groups using object model in feature activation but was not able to view the groups at the time of adding the user to created groups. Then searching the web come to a web property AssociatedGroups, which add the group to site group.
SPGroup sNewGroup;
SPRoleAssignment roleAssignment;
SPRoleDefinition permLevel;
string[] sGrupToSearch = { sGroupName };
SPGroupCollection spCurrentGroup = objSPWeb.SiteGroups.GetCollection(sGrupToSearch);
if (spCurrentGroup.Count < 1)
objSPWeb.SiteGroups.Add(sGroupName, objSPWeb.Site.Owner, objSPWeb.Site.Owner, sGroupName);
sNewGroup = objSPWeb.SiteGroups[sGroupName];
roleAssignment = new SPRoleAssignment(sNewGroup);
permLevel = objSPWeb.RoleDefinitions[strPermissionLevel];
roleAssignment.RoleDefinitionBindings.Add(permLevel);
objSPWeb.RoleAssignments.Add(roleAssignment);
objSPWeb.AssociatedGroups.Add(sNewGroup);
objSPWeb.Update();
SPGroup sNewGroup;
SPRoleAssignment roleAssignment;
SPRoleDefinition permLevel;
string[] sGrupToSearch = { sGroupName };
SPGroupCollection spCurrentGroup = objSPWeb.SiteGroups.GetCollection(sGrupToSearch);
if (spCurrentGroup.Count < 1)
objSPWeb.SiteGroups.Add(sGroupName, objSPWeb.Site.Owner, objSPWeb.Site.Owner, sGroupName);
sNewGroup = objSPWeb.SiteGroups[sGroupName];
roleAssignment = new SPRoleAssignment(sNewGroup);
permLevel = objSPWeb.RoleDefinitions[strPermissionLevel];
roleAssignment.RoleDefinitionBindings.Add(permLevel);
objSPWeb.RoleAssignments.Add(roleAssignment);
objSPWeb.AssociatedGroups.Add(sNewGroup);
objSPWeb.Update();
No comments:
Post a Comment