The below code works fine to get an Email ID from people picker field for an Item of a list.
string userEmailID = GetUserEmail(spListItem, "PeoplePickerfieldName");
public string GetUserEmail(SPListItem spListItem, string fieldName)
{
SPFieldUser spFieldUser = (SPFieldUser)spListItem.Fields[fieldName];
SPFieldUserValue spFieldUserValue = (SPFieldUserValue)spFieldUser.GetFieldValue(spListItem[fieldName].ToString());
return spFieldUserValue.User.Email;
}
string userEmailID = GetUserEmail(spListItem, "PeoplePickerfieldName");
public string GetUserEmail(SPListItem spListItem, string fieldName)
{
SPFieldUser spFieldUser = (SPFieldUser)spListItem.Fields[fieldName];
SPFieldUserValue spFieldUserValue = (SPFieldUserValue)spFieldUser.GetFieldValue(spListItem[fieldName].ToString());
return spFieldUserValue.User.Email;
}
No comments:
Post a Comment