lundi 12 janvier 2015

Set permission on ListItem level. Issue with usernames with Norwegian letters

I have created an EventReceiver that is setting permissions on ListItem level. I am having some problems with users having norwegian letters (æøå) in their username. For other users it works.


Under you will find a part of the code setting permissions. The EventReceiver is running with RunWithElevatedPrivileges.



if (properties.ListItem["Responsible_x0020_for"] != null)
{
//Removed Responsible_x0020_for_x0020_acti added Responsible_x0020_for
SPRoleAssignment roleAssignmentResponsibleAction = new SPRoleAssignment((SPPrincipal)web.AllUsers[GetUserFromAfterProperties(properties.ListItem["Responsible_x0020_for"], web).LoginName.ToString()]);
roleAssignmentResponsibleAction.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Contributor));
reporting.RoleAssignments.Add(roleAssignmentResponsibleAction);

}
else if (getSPUserValue(properties).LoginName != null)
{

SPRoleAssignment roleAssignmentResponsibleAction = new SPRoleAssignment((SPPrincipal)web.AllUsers[getSPUserValue(properties).LoginName.ToString()]);
roleAssignmentResponsibleAction.RoleDefinitionBindings.Add(web.RoleDefinitions.GetByType(SPRoleType.Contributor));
reporting.RoleAssignments.Add(roleAssignmentResponsibleAction);

}


The strange thing is that it works if the user is in a group, but not if it is a single user field. Maybe it is that the group is handled as the object vs the single user is handled as the object?


I have tested with several users containing æøå in their usernames.


Any help appreciated


Aucun commentaire:

Enregistrer un commentaire