I'm trying to create a new group by event receiver feature with this code, but when I deploy it nothing changes

public static void CreateSubSiteGroup(SPWeb web, string groupName, string PermissionLevel,string groupDescription)

            SPUserCollection users = web.AllUsers;
            SPUser owner = web.SiteAdministrators[0];
            SPMember member = web.SiteAdministrators[0];
            SPGroupCollection groups = web.SiteGroups;
            groups.Add(groupName, member, owner, groupDescription);
            SPGroup newSPGroup = groups[groupName];
            SPRoleDefinition role = web.RoleDefinitions[PermissionLevel];
            SPRoleAssignment roleAssignment = new SPRoleAssignment(newSPGroup);

    public override void FeatureActivated(SPFeatureReceiverProperties properties)

        string groupName="Donor";
        string groupDescription = "Group for Donors";
            using (SPWeb web = properties.Feature.Parent as SPWeb)
                CreateSubSiteGroup(web, groupName, "Full Control", groupDescription);
        catch (Exception ex)
            string message = ex.Message;

2 Answers 2


The very obvious mistake I can see is not to put properties.Feature.Parent as SPWeb in using..

using (SPWeb web = properties.Feature.Parent as SPWeb) shouldn't be used.. just like SPContext.Current.Web, you shouldn't dispose properties.Feature.Parent (you didn't create a new object anywhere.. so you are not responsible for disposing it)


Pls write your code



web.AllowUnsafeUpdates = true;


web.AllowUnsafeUpdates = false;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.