I am working on a SharePoint server 2013, and using the UI i can do the following:-
- Inside the site collection >>site settings >> site permission >>Create Group >> give it a name >> keep the owner as is (my username).
- create the group.
- edit the group
- define that the Group name is the owner.
- define that only group members can view the membership.
- define that Group owners can add members.
- go to a sub-site (which have unique permission), assign the new group and give it Contribute permission.
now i have an event receiver which get fired when an item is updated inside the sub-site. now inside this event receiver i am creating a new sub-site and i want to do the above 7 steps. i start wit the following :-
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(properties.SiteId))
{
string currenweburl = properties.RelativeWebUrl;
using (SPWeb spCurrentSite = site.OpenWeb(currenweburl))
{
SPWebCollection subWebs = spCurrentSite.Webs;
String curListName = properties.ListTitle;
//Get the SPListItem object that raised the event
SPListItem curItem = properties.ListItem;
//Get the Title field from this item. This will be the name of our new subsite
String curItemSiteName = properties.ListItem["Title"].ToString();
String curItemID = properties.ListItemId.ToString();
SPWeb rootWeb = spCurrentSite.Site.RootWeb;
String webTemplateName = "New Project Template"; //this is the name of the template we will use
//Create the subsite based on the template from the Solution Gallery
SPWeb newSite = spCurrentSite.Webs.Add(curItemID, curItemSiteName, "created automatically", Convert.ToUInt16(1033), webTemplate, false, false);
//Set the new subsite to inherit it's top navigation from the parent site, Use false if you do not want this.
//Code to cover the 7 Steps
site.RootWeb.SiteGroups.Add(curItemSiteName,**** , *****, "Your Group Description");
SPGroup group2 = site.RootWeb.SiteGroups[curItemSiteName];
// Add the group's permissions
SPRoleDefinition roleDefinition = site.RootWeb.RoleDefinitions.GetByType(SPRoleType.Contributor);
SPRoleAssignment roleAssignment = new SPRoleAssignment(group2);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
site.RootWeb.RoleAssignments.Add(roleAssignment);
site.RootWeb.Update();
but i got confused on how i need to implement my last block commented by //Code to cover the 7 Steps
.. as seems when creating new group some parameters is SPMember()
which other is SPUser()
.. and not sure where i define the setting to force only members to view the group members. can anyone advice on this please?