Get SPUser from User Column
There are two ways to get the SPUser object from the User Column of list item.
1. User SPFieldUserValue constructor
SPFieldUserValue value = new SPFieldUserValue(item.ParentList.ParentWeb, userName);
SPUser user = value.User;
2. Use SPFieldUser's GetFieldValue
SPFieldUser userField = item.Fields[fieldName] as SPFieldUser;
string userName = item[fieldName] as string;
SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(userName);
SPUser user = fieldValue.User;
string userName = item[fieldName] as string;
SPFieldUserValue fieldValue = (SPFieldUserValue)userField.GetFieldValue(userName);
SPUser user = fieldValue.User;
No comments:
Post a Comment