0

I'm trying to add a user in a group during my event itemupdated.

Like this he has the necessary permission to move a file and after I remove him from group.

I've tried this to add but nothing appears in the group and the code runs correctly in debug:

//manage permission to delete 
SPUser user = Web.CurrentUser;
SPGroup groupAdmin = Web.Groups["Admin test"];
bool permToRemove = false;
if (user != null && groupAdmin != null)
{
    if (!Web.IsCurrentUserMemberOfGroup(groupAdmin.ID))
    {
        groupAdmin.AddUser(user);
        permToRemove = true;
        user.Update();
    }
}

I'm in a sandbox solution.

  • Is this an event receiver? Is web the root web of the site collection? Also any reason why user.Update() us being used when you are not updating its properties? – Sudhakar Jul 7 '14 at 10:27
  • Can you confirm that Web.CurrentUser is not a system account or null? Since your code is executed inside of ItemUpdated not ItemUpdating, HttpContext is currently null and user may be unknown at this point. – Marek Kembrowski Jul 7 '14 at 10:40
  • i'm at the root of the site inside event receiver itemupdated. It's not a system account and nothing is null because it goes in my if condition. Are there an other way to update user? i tryied too update group without success – user1898765 Jul 7 '14 at 12:52

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.