Sometimes, you need to get
SPUser object(to retrieve email, name,...) , however you have only
SPListItem with
SPFieldCollection. When you try to retrieve it, for example:
var field = item["user"]
you just get a string with User ID , like : "123;#"
This C# code can help us:
public SPUser GetSPUserObject(SPListItem spListItem, String fieldName)
{
SPUser spUser = null;
try
{
if (fieldName != string.Empty)
{
SPFieldUser field = spListItem.Fields[fieldName] as SPFieldUser;
if (field != null && spListItem[fieldName] != null)
{
SPFieldUserValue fieldValue = field.GetFieldValue(spListItem[fieldName].ToString()) as SPFieldUserValue;
if (fieldValue != null)
{
spUser = fieldValue.User;
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return spUser;
}