Wednesday, 14 April 2010

Convert PersonOrGroup field to SPUser

There is no straight way to convert "personorgroup" field to SPUser object. Here the way to convert it using SPFieldUser object.



private
SPUser GetUser(SPListItem item, SPField userField)
{
string currentValue = item[userField.Title].ToString();
SPFieldUser field = (SPFieldUser)userField;
SPFieldUserValue fieldValue = (SPFieldUserValue)field.GetFieldValue(currentValue);
return fieldValue.User;
}

No comments:

Post a Comment