CSC510251. Do not use EntityEditor.Entities collection.

Description

It is not recommended to use the Entities property to get the selected entities, because using this sometimes causes unexpected behavior.

Resolution

It’s much more reliable to use ResolvedEntities instead.

public static SPPrincipalInfo GetPeoplePickerUser(ControlCollection controlCollection)
{
    SPPrincipalInfo result = null;
    foreach (Control control in controlCollection)
    {
        var peopleEditor = control as PeopleEditor;
        if (peopleEditor != null && peopleEditor.Entities.Count == 1)
        {
            PickerEntity pickerEntity = (PickerEntity)peopleEditor.Entities[0];
            // get principal info code here ...
            return result;
        }
        if (control.HasControls())
        {
            result = GetPeoplePickerUser(control.Controls);
        }
    }
    return result;
}

Links

EntityEditor.Entities property
EntityEditor.ResolvedEntities property

Last edited Aug 1, 2014 at 8:52 AM by dvd73, version 1

Comments

No comments yet.