Click here to Skip to main content
14,487,386 members

PeopleEditor Control

Rate this:
2.81 (12 votes)
Please Sign up or sign in to vote.
2.81 (12 votes)
15 Jan 2008CPOL
How to get data from PeopleEditor Control

Introduction

The PeopleEditor control belongs to the SharePoint 2007 family of controls and permits WebParts to interact with ActiveDirectory through research and selection of AD objects, respecting a basic MOSS user interface. This article's scope isn’t principally to illustrate the characteristics of the control class (for that, it is enough to visit Microsoft's MSDN), but rahter the basic use in a WebPart. On top of that, it also aims to discuss the necessary code to read properties' AD objects that a user has selected, code that makes use of the PickerEntity class.

Use Case Description

The sample will show the PeopleEditor control, with a user that chooses from among available objects in ActiveDirectory (for instance, 2 domain users). Then we will examine the code written for a button click event to load a grid with AD objects' data.

WebPart

The WebPart by graphical view is shown in the following image. This happens after the user has selected some objects in AD and loaded data into the grid, clicking the button “Read entity.”

image001_small.PNG

The Code

The code is written in a simple manner to focus attention on the use of the PeopleEditor control. The button and the grid (GridView control) are used just to display AD objects' data and thus are only to support the sample. For this, interesting code is isolated in a separate routine named GetEntities(), which is called by the button click event. The following shows the routine GetEntities().

private bool GetEntities()
{
    try
    {
    // 1. following 2 lines load data into Entities ArrayList
    ArrayList
    aAccount = new ArrayList();
    aAccount = _PE.Accounts;

    //-------------------------------------------------------

    ArrayList peEntities = _PE.Entities;
    ArrayList AL = new ArrayList();
 
    for (int i = 0; i < _PE.Entities.Count; i++)
    {
        // 2. cast object Entities in PickerEntity class
        PickerEntity pickEn = (PickerEntity)peEntities[i];
        Hashtable hstEntityData = pickEn.EntityData;

        // 3. clsPickEntity is a custom class to store data
        clsPickEntity cPickEnt = new clsPickEntity();
        cPickEnt.DisplayName = Convert.ToString(hstEntityData["DisplayName"]);
        cPickEnt.Email = Convert.ToString(hstEntityData["Email"]);
        cPickEnt.LoginName = pickEn.Key;
        cPickEnt.SPUserID = Convert.ToString(hstEntityData["SPUserID"]);
        cPickEnt.Department = Convert.ToString(hstEntityData["Department"]);
        cPickEnt.PrincipalType = Convert.ToString(hstEntityData["PrincipalType"]);
        cPickEnt.SIPAddress = Convert.ToString(hstEntityData["SIPAddress"]);
        cPickEnt.Title = Convert.ToString(hstEntityData["Title"]);

        // 4. load custom class to custom ArrayList
        AL.Add(cPickEnt);
    }

    // 5. fill data into GridView
    _GV.AutoGenerateColumns = true;
    _GV.DataSource = AL;
    _GV.DataBind();
    return true;
    }
    catch (Exception ex)
    {
        // Manage error event
        return false;
    }
}
  1. To start, it is necessary call the Accounts method of the PeopleEditor object. This is out of our scope, but it is useful to force the loading of ArrayList entitites which otherwise -- probably a bug of the PeopleEditor control -- will not always be properly filled.
  2. At this point, it is possible to cycle inside ArrayList entities exposed by the PeopleEditor control and mostly set casting of an item as a PickerEntity object (for details, see this).
  3. For more code usability, it is convenient to assign the Hashtable EntityData of the PickerEntity object to a custom class, mapping in this way the object's properties to our custom class properties.
  4. To easily and quickly show data with a grid, we are going to load an ArrayList with our custom class.
  5. Finally, perform grid binding to the data source.

For further precision, see the following image of the PickerEntity object model with AD data.

image003.png

Conclusion

The PeoplePicker object used together with PickerEditor is useful to allow a SharePoint user to interact with ActiveDirectory from SharePoint. It also makes an important functionality available to the developer in an easy way, by writing just a few code lines.

History

  • 15 January, 2008 -- Original version posted

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Fabio Barbieri
Ireland Ireland
I am Microsoft analyst and developer

Comments and Discussions

 
QuestionHow to get other user's information using people editor control Pin
Suresh Kumar.A6-Dec-11 6:13
MemberSuresh Kumar.A6-Dec-11 6:13 
QuestionWant to implement in desktop application Pin
fine_dost29-Sep-11 23:43
Memberfine_dost29-Sep-11 23:43 
GeneralMy vote of 1 Pin
Eng. Jamil H. Haddadin23-Mar-10 12:15
MemberEng. Jamil H. Haddadin23-Mar-10 12:15 
General[My vote of 2] Aspx code or sample project [modified] Pin
Thymine4-Sep-09 9:04
MemberThymine4-Sep-09 9:04 
QuestionPeopleEditor Control Pin
Anwarul18-Jan-09 22:34
MemberAnwarul18-Jan-09 22:34 
GeneralMy vote of 1 Pin
SergioOrru12-Jan-09 1:05
MemberSergioOrru12-Jan-09 1:05 
GeneralMy vote of 1 Pin
SergioOrru12-Jan-09 1:04
MemberSergioOrru12-Jan-09 1:04 
GeneraleMail item AD Only Pin
CyberJetX8-Jul-08 5:11
MemberCyberJetX8-Jul-08 5:11 
GeneralPostback problem with peopleeditor Pin
Member 22681947-Jul-08 0:56
MemberMember 22681947-Jul-08 0:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Article
Posted 15 Jan 2008

Stats

65.3K views
1 download
24 bookmarked