0

I have 2 groups namely NPD ADMIN and NPD SPUSERS

AT THE DOC.LIb level, I have permisionss set as

  1. `NPD ADMIN` : `CONTRIBUTE`
  2. `NPD SPUSERS` : `CONTRIBUTENODELETE`

I want to remove the existing permissions for NPD SPUSERS group from contributenodelete to read when an item is added in this doc.lib. so i added an eventreceiver and i added the itemadded() methods i treid to add the code to implement this business usecase.

but its not happening. can anyone help, how to achieve this?

        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite CurrentSite = new SPSite(properties.SiteId);
                SPWeb CurrentWeb = 
             CurrentSite.OpenWeb(properties.RelativeWebUrl);
                CurrentWeb.AllowUnsafeUpdates = true;
                SPList CurrentList = CurrentWeb.Lists[properties.ListId];
                SPListItem CurrentListItem;
                CurrentListItem = 
        CurrentWeb.Lists[properties.ListId].GetItemById(properties.
      ListItem.ID);
           SPDocumentLibrary objProjdocLib = CurrentList as 
          SPDocumentLibrary;

                SPGroup npdadminGroup = CurrentWeb.SiteGroups["NPD Admin"];
                SPGroup npdspusersGroup = CurrentWeb.SiteGroups["NPD 
          SPUsers"];

                SPFieldUserValue userValue = new 
            SPFieldUserValue(CurrentWeb, 
          CurrentListItem[SPBuiltInFieldId.Author].
         ToString());
                SPUser objspauthor = userValue.User;
                SPListItemCollection configILPItemCollection = null;

                     if ((!CurrentListItem.HasUniqueRoleAssignments))
                        {
                            CurrentListItem.BreakRoleInheritance(false);
                            CurrentWeb.AllowUnsafeUpdates = true;
                        }

                //SPGroup group = root.SiteGroups[groupName];

                             SPRoleDefinition contributeRoleDef = 
          CurrentWeb.RoleDefinitions.GetByType(SPRoleType.Contributor);
                SPRoleDefinition contributeRoleDef1 = 
        CurrentWeb.RoleDefinitions.GetByType(SPRoleType.Contributor);

                //SPRoleDefinition contributeRoleDef = 
        CurrentWeb.RoleDefinitions["ContributeNoDelete"];
                //SPRoleDefinition readerRoleDef = CurrentWeb.RoleDefinitions.GetByType(SPRoleType.Reader);

                SPRoleDefinition readerRoleDef = 
            CurrentWeb.RoleDefinitions["ContributeNoDelete"];
                  SPRoleAssignment groupRoleAssignments = 
           CurrentWeb.RoleAssignments.GetAssignment
        ByPrincipal(npdadminGroup);
                //groupRoleAssignments.RoleDefinitionBindings.Remove(contributeRoleDef1);
                SPRoleAssignment groupRoleAssignments1 = CurrentWeb.RoleAssignments.GetAssignmentByPrincipal(npdspusersGroup);
                groupRoleAssignments1.RoleDefinitionBindings.Remove(contributeRoleDef);
                //groupRoleAssignments.RoleDefinitionBindings.Add(readerRoleDef);
                //groupRoleAssignments.Update(); 

               CurrentListItem.RoleAssignments.Add(groupRoleAssignments);
               CurrentListItem.RoleAssignments.Add(groupRoleAssignments1);

                CurrentListItem.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.