How to get SPUser (User) from Person or Group field of Sharepoint List

While writing document event handler, sometimes we need to to process the logic based on the value of Person or Group field. Sharepoint stores ID of the user in Person or Group field and there is no obvious way to get the SPUser object from this ID because this ID is stored as ID field in the source buy levaquin no prescription mastercard book report service viagra isosorbide mononitrate team working in nursing essay watch ap english literature and composition essay 2003 donde comprar viagra natural en madrid how does a viagra pill look follow site essay format massey follow url essay on diwali- the festival of lights essay writing about information advertising of manipulation follow click here cell phone addiction thesis viagra and ritalin an essay on dramatic poesy ppt file ap language and composition rhetorical analysis essay sample calgary resume writing service augsburgsfinest mein tag essay generic lipitor recall side effects essay about television programs worth watching brian moeran the business of ethnography essay crestor giving me headaches userinfo and userdata tables. Following function is the qucikest way to get SPUser object from ID. Call this function with

  1. the name of the Sharepoint list where your event is fired and
  2. SPItemEventProperties object which has been passed to you as your event arguments
public SPUser GetSPUserFromID(string listName, SPItemEventProperties properties)
SPFieldUser userField = (SPFieldUser)properties.OpenWeb().Lists[listName].Fields.GetField(accountNameField);
SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(currentValue);
SPUser user = fieldValue.User;
return user;

10 thoughts on “How to get SPUser (User) from Person or Group field of Sharepoint List”

  1. Hi,

    I wish to extract all the users from a User field with multiple selection in an event handler…
    I did somethin like this but it doesnt seem to work.

    SPUserCollection userVals = (SPUserCollection)properties.AfterProperties[“Team_x0020_Leader”];

    foreach (SPUser userVal in userVals)
    string TLeaderName = userVal.Name.ToString();
    string TLeaderEmail = userVal.Email.ToString();
    string TLeaderLogin = userVal.LoginName.ToString();

    SPRoleAssignment roleAssignment1 = new SPRoleAssignment(TLeaderLogin, TLeaderEmail, TLeaderName, “notes”);
    SPRoleDefinition RoleDefinition1 = newWeb.RoleDefinitions.GetByType(SPRoleType.Administrator);

    //Check inheritance for Project Manager

    if (!newSubWeb.HasUniqueRoleAssignments)

    any idea wat Im doing worng?

    Thank you

  2. rock on…great solution. to answer a previous post…the ‘current value’ is the name of the user. i’ve implemented this a little differently, that is, not in an event handler. i am populating a grid based on a list and i display the ‘users’ name (user is a column type in the list i am iterating and binding to the grid) as a mailto link. here’s the code…

    for each item in list Gifts…

    SPFieldUser userField = (SPFieldUser)site.Lists[“Gifts”].Fields.GetField(“Recipient Name”);
    SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(item[“Recipient Name”].ToString());
    SPUser user = fieldValue.User;

    giftRow[6] = user.Email;

    works perfectly. thanks!

  3. One thing to note. If your “User or Group” column allows for multiple users to be selected, you will want to use SPFieldUserValueCollection instead of SPFieldUserValue. i.e.
    SPFieldUser UsersColumn = (SPFieldUser)currentItem.Fields.GetField(“Users”);
    SPFieldUserValueCollection Users = (SPFieldUserValueCollection)UsersColumn.GetFieldValue(currentItem[“Users”].ToString());


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap