Thursday, October 25, 2012

Account name from People picker



        We have person and group column in sharepoint.
We can specify what should be displayed in that field like Name,Account,Work-Email etc.
If u set it to Name for client purpose and you want Account name for other programming use you can use the following code.

string strName = GetUser(item, item.Fields["Discipline Approver"]).Name;


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