Question : MOSS People Picker

In the below code, I am not getting values for values[0].User.Name as null for some users, while  not null for some other users.... Any pointers? Little urgent please :-)

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
private void SetPeopleInfo(SPListItem listItem)
        {
            SPFieldUserValueCollection values = new SPFieldUserValueCollection();

            for (int i = 0; i < pplEditor.ResolvedEntities.Count; i++)
            {
                PickerEntity picker = (PickerEntity)pplEditor.ResolvedEntities[i];

                SPFieldUserValue userValue = new SPFieldUserValue(GetWeb(),
                                                                    Convert.ToInt32(picker.EntityData[PeopleEditorEntityDataKeys.UserId]),
                                                                    picker.Description);
                values.Add(userValue);
            }
            if (values.Count > 0)
            {
                listItem["__AssignedToName"] = values[0].User.Name;
                listItem["__AssignedToEmail"] = values[0].User.Email;
                listItem["__AssignedTo"] = values.ToString();
            }
            else
            {
                listItem["__AssignedToName"] = null;
                listItem["__AssignedToEmail"] = null;
                listItem["__AssignedTo"] = null;
            }
        }

Answer : MOSS People Picker

Thanks a ton for your reply.

I solved the issue like this.

PickerEntity picker = (PickerEntity)pplEditor.ResolvedEntities[i];
string userid = picker.EntityData[PeopleEditorEntityDataKeys.UserId];
string email= picker.EntityData[PeopleEditorEntityDataKeys.Email];                                                                    

For some reason the user object is not found for all the users.It is just a workaround that worked for me. Would be investigating further on a later point in time.
Random Solutions  
 
programming4us programming4us