none
how i can set the newly created Group as self-owner inside my event reciever RRS feed

  • Question

  • I am working on sharepoint 2013 server , and i have the following event reciever where i am creating new user group inside a sub-site:-

    public override void ItemUpdated(SPItemEventProperties properties)
        {
    
        base.ItemUpdated(properties);
    
    	var currentusername = properties.UserLoginName;
    	site.RootWeb.SiteGroups.Add(curItemSiteName, site.RootWeb.SiteUsers[@"domain\" + currentusername], site.RootWeb.SiteUsers[@"domain\" + currentusername], "Some description");
    	SPRoleAssignment ra = new SPRoleAssignment(site.RootWeb.SiteGroups[curItemSiteName]);                 
    	ra.RoleDefinitionBindings.Add(site.RootWeb.RoleDefinitions["Contribute"]);
    	newSite.RoleAssignments.Add(ra);
    	site.RootWeb.RoleAssignments.Add(ra);
            site.RootWeb.Update();
    	}

    but i m not sure how i can do these 2 modifications:-

    1. from the UI i can set these 2 options when creating a new user group:-

    so is there a way to do so using my above code?

    2. currently i am adding the user who executed the event receiver as the "Group Owner"... but my question is how i can modify my above code to assign the newly create group as the "Group Owner". in other word members of the Group will be the "Group owners"??

    Friday, January 13, 2017 1:34 PM

Answers

  • 1. Once you create group get the group to set the properties and then call update.

    SPGroup group = web.SiteGroups["GROUPNAME"] //Change this code as needed. Basically you need to grab the SPGroup that you just created.

    Then use the following.

    group.Owner = (SPMember)group; //Not tested this but basically you need to cast your SPGroup to SPMember to set Owner.

    group.OnlyAllowMembersViewMembership = true/false;

    group.AllowMembersEditMembership = true/false

    group.AllowRequestToJoinLeave = true/false

    Finally call group.Update()



    Amit

    • Marked as answer by johnjohn11 Saturday, January 14, 2017 2:39 AM
    Friday, January 13, 2017 2:25 PM