I want to get the user value from the Person or Group column in code behind.
My code is:
List<string> manager = GeneralMethods.GetUsers((SPFieldUserValueCollection)item[FieldNames.Manager]);
List<string> owner = GeneralMethods.GetUsers((SPFieldUserValueCollection)item[FieldNames.ProjectOwner]);
The method code is:
public static List<string> GetUsers(SPFieldUserValueCollection users)
{
List<string> listUsers = new List<string>();
if (users.Count != 0)
{
foreach (SPFieldUserValue field in users)
{
SPUser user = field.User;
listUsers.Add(user.LoginName);
}
}
return listUsers;
}
My problem is that manager
assigned successfully but when the control comes to owner
then the above mentioned error is thrown. Here the item[FieldNames.ProjectOwner])
is the person or group column which accepts single value only.
What am I missing?