Getting SPUser from SharePoint List Column
In the project I was working on right now, I had to get a User field from a SharePoint User colum. The value is stored as a lookup column and in order to get it as a SPUSER I had to write the following utility method
public static SPUser GetUser(string columnValue, SPField userField)
{
SPFieldUser field = (SPFieldUser)userField;
SPFieldUserValue fieldValue = (SPFieldUserValue)field.GetFieldValue(columnValue);
return fieldValue.User;
}
To get the SPUSer filed now, we just call the method as follows
string managerColumnValue =
nominationListItem[NominationListColumns.MANAGER].ToString();
SPUser manager = Utilities.GetUser(managerColumnValue,
nominationListItem.Fields[NominationListColumns.MANAGER]);
where
NominationListColumns.MANAGER = "Manager", which is the column name..


Comments