Summary : How to Create SpsecurityEventReceiver in SharePoint 2013,Create a GroupUserAdded() SPSecurityEventReceiver EventReceiver in SharePoint 2013,sharepoint 2013 event receivers,SharePoint 2013,SPSecurityEventReceiver in SharePoint 2013,GroupUserAdded() Event Receiver
Part 1 in this post we will look at how to create GroupUserAdded() SPSecurityEventReceiver EventReceiver and it works.
Step 6 –
Add a new Class file “UserAddedEventReceiver.cs” to your project.
Step 7 – Make sure that your class inherits SPSecurityEventReceiver class. Add the following Code for GroupUserAdded() in your UserAddedEventReceiver class.
class UserAddedEventReceiver : SPSecurityEventReceiver
public override void GroupUserAdded(SPSecurityEventProperties properties)
//Get the user being added
SPUser addedUser = properties.Web.AllUsers.GetByID(properties.GroupUserId);
if (addedUser != null && properties.GroupId == 8)
SPGroup spGroup = properties.Web.Groups["Added Members"];
if (spGroup != null)
The code should look something like below.
Step 8 – Once the code is added Start and debug the project.The project will add the solution in your site and activate the feature as well. Feature activation will kick off the Feature Receiver and registers the GroupUserAdded() events.
Step 9 – Once the solution is deployed verify if the Feature is activated.To do this navigate to your SharePoint site -> Settings -> Manage site Features. In the feature list look for “GroupUserAddedEventReceiver Feature 1” feature.
Step 10 – Now Navigate to the People and groups -> Team Site Members to add a new user. Follow the screens below –
Finally, as per the EventReciver the user “Administrator” when gets added to “Team Site Members” also gets added to “Added Members” group in the same site.