I have an event receiver on itemAdded. I set some permissions like below.
SPRoleAssignment role = new SPRoleAssignment(spPrincipal);
role.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Contributor));
listItem.RoleAssignments.Add(role);
Do I have to execute also the Update method to save the changes? Like this:
listItem.Update();
UPDATE:
This is the code:
public static void SetMemberShipToListItem(List<SPPrincipal> userAndGroups, SPListItem listItem, SPWeb web)
{
if (listItem.HasUniqueRoleAssignments)
{
listItem.ResetRoleInheritance();
}
listItem.BreakRoleInheritance(false);
foreach (SPPrincipal spPrincipal in userAndGroups)
{
// set permission for current user (creator of this listitem)
if (spPrincipal != null)
{
SPRoleAssignment role = new SPRoleAssignment(spPrincipal);
role.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Contributor));
listItem.RoleAssignments.Add(role);
}
}
//listItem.Update();
}