Karine Bosch’s Blog

On SharePoint

PeopleEditor Control


Introduction

The PeopleEditor control is a great control to easily select one or more users from the users known in the directory service of the server.

peopleeditor

The control consists of 3 controls:

  • a text box where you can fill out part or complete user name
  • a button to check the filled out name(s)
  • a Browse button to search for a user name

When you click the Browse button a dialog opens where you can search for specific user(s).

peoplepicker

When you entered part of a name and click the Check Names button the entrance is checked agains the users in the directory service. When no exact match is found, the value is marked with a red line. Clicking on it will display a list with all matches from which you can select one.

peopleeditor-match

 

Syntax

You can use this PeopleEditor control when developing application pages or control templates using the following syntax:

<spuc:PeopleEditor ID="PeopleEditor1" runat="server" width="350px"
                   AllowEmpty="true" MultiSelect="false" SelectionSet="User"  />

But only after you have added a directive at the top of the application page or control template:

<%@ Register TagPrefix="spuc" Namespace="Microsoft.SharePoint.WebControls"
             Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

If you are developing a web part you have to create the PeopleEditor control completely in code:

private PeopleEditor peopleEditor;
private void EnsureChildControls()
{
    peopleEditor = new PeopleEditor();
    peopleEditor.AutoPostBack = true;
    peopleEditor.ID = "PeopleEditor1";
    peopleEditor.AllowEmpty = false;
    peopleEditor.MultiSelect = false;
    Panel1.Controls.Add(peopleEditor);
}

This control is part of the Microsoft.SharePoint.dll and is located in the Microsoft.SharePoint.WebControls namespace.

 

Properties

There are also a number of properties/attributes you can set to configure the functionality of the PeopleEditor control:

  •  AutoPostBack: if you want the control to react immediately when a user works with it, you have to set this property to true. Otherwise the control will react on page postback.
  • AllowEmpty: Setting this to false obliges the user to fill out a user name. The default value is true. (Pay attention to this property: I was not able to make it work, and I’m not the only one).
  • AllowTypeIn: Setting this property to false prevent users from filling out part of a name or complete name. In this case users can only use the Check Names button and Browse button to populate the control.
  • CommaSeparatedAccounts: you can initialize the PeopleEditor control by entering a string of login names separated by a comma.
  • EntitySeparator: the default is a ‘;’.
  • ErrorMessage: you can change the default message by setting this property to a custom error message.
  • ID: id of the control.
  • MultiSelect: Setting this property to true allows users to select more than one user.
  • NoMatchesText: you can change the default message that is displayed when no matches are found by setting this property to a custom error message.
  • PlaceButtonsUnderEntityEditor: Setting this property to true displays the Check Names button and Browse button under the text box. The default is false.
  • PrincipalSource: if you have more than one source from where users can be selected, you can set this property to the desired source.
  • SelectionSet: this property accepts a comma-delimited string containing the different account types (defined in the AccountType enumeration) like User, DL, SecGroup, SPGroup
      objEditor.SelectionSet = "User,SecGroup,SPGroup";
  • SharePointGroup: you can also limit the users that can be selected in the PeopleEditor control by setting this property to the name of a SharePoint group defined on the current web.
  • ShowButtons: set this property to false if you don’t want to have the Check Names and Browse button displayed.
  • ValidatorEnabled: if set to true, the entries in the text box are validated client-side.
  • ValidateResolvedEntity: the default value is true to validate the resolved entity. You can set this property to false to prevent validation. 

The list above is not complete. You can find the complete list on MSDN

 

Methods

There are also a number of methods you can use:

  • GetAccountFromSid: Retrieves the login name of an account associated with the security ID (Sid) that is passed into this method.
  • UpdateEntities: you can use this method to f.e. initialize the PeopleEditor control.
      // populate the PeopleEditor with the current user
      System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();
      PickerEntity entity = new PickerEntity();
      entity.Key = SPContext.Current.Web.CurrentUser.LoginName;
      // this can be omitted if you're sure of what you are doing
      entity = PeopleEditor1.ValidateEntity(entity);
      entityArrayList.Add(entity);
      PeopleEditor1.UpdateEntities(entityArrayList);
  • ValidateEntity: calling this method passing in an object instance of type PickerEntity ensures that the user exists in the directory service.
      entity = PeopleEditor1.ValidateEntity(entity);
 

Objects

When the CheckNames button is clicked a number of properties are populated by the internals of the control. You can inspect these properties:

  • Accounts: this is an ArrayList of strings and contains the login names of all selected users 
  • Entities: the contents of this property is unpredictable and I advise you not to use it. Use the ResolvedEntities property instead.
  • ResolvedEntities: this is an ArrayList of PickerEntity objects (more details below)

The PickerEntity object contains following properties:

  • Description: contains the login name of the user
  • DisplayText: contains the display name of the user
  • IsResolved: a boolean indicating whether the user was found in the directory service
  • Key: contains the login name of the user
  • EntityData: is an object with user data

The EntityData object consists of the following properties:

  • DisplayName
  • Email
  • Department
  • Title
  • PrincipleType

The PickerDialog is a property of the the PeopleEditor control and represents the dialog that is displayed when the user clicks the Browse button.

 

Retrieving User Profile

One of my readers recently asked if it was possible to retrieve the user profile based on the selected user in the PeopleEditor control. Working with user profiles is only possible if you have a Shared Services Provider installed and the have the user profiles imported.

User Profile information can programmatically be accessed throught the UserProfileManager class. This class is located in the Microsoft.Office.Server.dll.

With the outcome of the PeopleEditor control you can show user profile details of the selected user. The Key property of the PickerEntity object contains the login name of the user. This value can be used to retrieve the user profile from the User Profile Manager.

        // retrieve profile information
        ServerContext ctx = ServerContext.GetContext("Litware SSP");
        UserProfileManager mgr = new UserProfileManager(ctx);
        try
        {
          PickerEntity selectedEntity = (PickerEntity)PeopleEditor1.ResolvedEntities[0];
          UserProfile profile = mgr.GetUserProfile(selectedEntity.Key);
          AddProfileRow("Title", profile["Title"].Value.ToString());
          AddProfileRow("Department", profile["Department"].Value.ToString());
          AddProfileRow("Email", profile["WorkEmail"].Value.ToString());
          if (profile.PersonalSite != null)
            AddProfileRow("Personal site", profile.PersonalSite.Url);
        }

Remark: The AddProfileRow method is a private method that adds a row and two cells to the UserProfileTable.

If you want to show all properties of the user profile, you can loop through the defined properties and retrieve them from the user profile:

        PickerEntity selectedEntity = (PickerEntity)PeopleEditor1.ResolvedEntities[0];
        UserProfile profile = mgr.GetUserProfile(selectedEntity.Key);
        //Get the properties
        PropertyCollection props = mgr.Properties;
        foreach (Property prop in props)
        {
          if (profile[prop.Name] != null && profile[prop.Name].Value != null)
             AddProfileRow(prop.Name, profile[prop.Name].Value.ToString());
          else
            AddProfileRow(prop.Name, string.Empty);
        }

userprofile

 

But what if you want to use this control from within a web part?

When trying to use this control from within a web part (the classic web part for SharePoint 2007 or the Visual Web Part for SharePoint 2010), all of a sudden the PeopleEditor textbox is not visible anymore:

Unless you place it within a <div> element with a background color different from white:

<div style="background-color: Aqua">
    <spuc:PeopleEditor ID="PeopleEditor1" runat="server" Width="350px" AllowEmpty="true" MultiSelect="false" SelectionSet="User" />
</div>

resulting in

But propably this is not what you want. If you really really want a similar behavior as in a SharePoint application page with a border around the text box, you have to override some styles:

<style  type="text/css">    
    .ms-inputuserfield{ font-size:8pt; font-family:Verdana,sans-serif; border:1px solid #a5a5a5;}  
    div.ms-inputuserfield a{color:#000000;text-decoration: none;font-weight:normal;font-style:normal;}    
    div.ms-inputuserfield{padding-left:1px;padding-top:2px;}    
</style>  
<spuc:PeopleEditor ID="PeopleEditor1" runat="server" Width="350px" AllowEmpty="true" MultiSelect="false" SelectionSet="User" />

And this results in the desired layout:

 

123 Comments »

  1. thanks
    so usefull

    Comment by vedat | May 4, 2009 | Reply

  2. THis is a great article on people picker control.

    It helped me a lot.
    I used the below code to access email id and name
    PickerEntity pickerEntity = (PickerEntity) pplEditor.ResolvedEntities[0];
    Hashtable hash = pickerEntity.EntityData;
    Label1.Text = hash[“DisplayName”].ToString() + ” ; ” + hash[“Email”].ToString();

    thanks

    Comment by vishnu | June 20, 2009 | Reply

  3. Any idea on how to make AllowEmpty to work or validate empty input box ?

    Comment by Leonid Fofanov | June 23, 2009 | Reply

    • Hi Leonid

      It´s a little late for the response but I could make it work setting the properties AllowEmpty and ValidatorEnabled both to true.

      Great Post BTW

      Comment by Claudio | January 12, 2011 | Reply

  4. Nope, I was not able to make this work and I’m not the only one. You can combine this control with the ASP.NET RequiredFieldValidator.
    Karine

    Comment by Karine | June 23, 2009 | Reply

  5. Thanks a lot. Concise and informative just as an article should be.

    Comment by Siegfried Glaser | June 30, 2009 | Reply

  6. This is a great posting, but how do I retrieve Phone and Fax? Phone and Fax are fields that exist in AD, yet they are not in the EntityData object.

    Comment by D-J | September 15, 2009 | Reply

  7. Hi Karine,

    Thanks for the assembled information about the PeopleEditor and DateTimeControl controls in your other post. These posts made it more easier for me to create this little tool that can be used to change list item system properties from the user interface:
    http://pholpar.spaces.live.com/blog/cns!2CD45589973F2849!201.entry

    Regards,
    Peter

    Comment by Peter Holpar | October 12, 2009 | Reply

  8. Karine, please help me understand the way to extend the People Picker in the SharePoint GUI to return distribution groups. I know about the SelectionSet property but I do not want two controls: the People Picker and my own custom “Groups Picker”

    Comment by Kristopher | October 27, 2009 | Reply

  9. Hi,
    I have one query related with people picker.
    I want to allow to search only those users who are assigned for respective project in people picker.
    I am explaining you my requirement in details:
    I have tow custom lists.
    One is CustomList_Project:
    In CustomList_Project custom list, i have following columns:
    1) Project name: Textbox(User enter project name)
    2) Assigned To: People picker(User assigned for this project)

    Second is: CustomList_Second
    1) Project name(which is lookup control and whose values come from CustomList_Project(which is custom list)
    2) GetProjectOwner : People picker: When i select project name then it would only allow to search those users who have assigned for this project.
    (By default it is comming all users)

    Regards,
    Viraj Vashi

    Comment by Viraj Vashi | November 6, 2009 | Reply

    • Did you manage to get this done. I have a similar requirement.

      Comment by AdiG30 | October 28, 2010 | Reply

  10. Hi Viraj,
    Thanks for reading my blog post. Can you please post your question to the MSDN forum at http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/threads/.
    Greetz,
    Karine

    Comment by Karine Bosch | November 7, 2009 | Reply

  11. […] not too exciting. It contains only a DateTimeControl for both created and modified dates, and a PeopleEditor control for both created by and modified by. This file is located by default in C:Program […]

    Pingback by Changing system properties for an item from the SharePoint user interface – part 1 « Second Life of a Hungarian SharePoint Geek | December 3, 2009 | Reply

  12. Thank you very much! I played a little bit and found the following:

    To find out whether the input was valid, use:

    peoplePicker.Validate();
    if (peoplePicker.IsValid) …

    After having called Validate, the “Entities” property always contains all inputs including the ones which could not be resolved.

    IsValid is false if:
    * One or more inputs could not be resolved
    * There are more inputs than allowed (e.g. more than one)
    * The field is left empty but “AllowEmpty” is false

    Comment by darkroastjava | January 12, 2010 | Reply

  13. […] the second part of the CreateChildControls method I look up the child DateTimeControl and PeopleEditor controls of the field and set their content based on the values stored for the current list […]

    Pingback by Changing system properties for an item from the SharePoint user interface – part 2 « Second Life of a Hungarian SharePoint Geek | February 15, 2010 | Reply

  14. thanks a lot. love your site

    Comment by duong | April 13, 2010 | Reply

  15. NoMatchesText: you can change the default message that is displayed when no matches are found by setting this property to a custom error message.

    Are you sure?
    NoMatchesText is Read-Only property…

    Comment by Comunistoide | June 15, 2010 | Reply

  16. The property peopleeditor.sharepointgroup lets me set to only one SP group. Can you please tell me how to give multiple groups. I want to show users if they are existing in any one of our SP groups.
    Thanks

    Comment by Reddy | July 11, 2010 | Reply

  17. Hi, thanks for this post, and i have followed as mentioned.im getting the following error “‘User’ could not be set on Property SelectionSet.

    Comment by Akila | July 28, 2010 | Reply

  18. […] sehr guter Blog-Beitrag hierzu gibt es von Karine Bosch [SharePoint MVP]. Auch ist hier erklärt wie man durch ein User Profile iteriert und alle Informationen zurück […]

    Pingback by Der PeopleEditor - Starcoder | August 2, 2010 | Reply

  19. Hi Karine
    can i set the properties BorderWidth programmatically.
    I can try to use:

    PeopleEditor pEditor = new PeopleEditor();
    pEditor.Style.Add(“BorderWidth”,”1px”);

    in my Page_Load but this method don’work😦

    Can you help me????
    Thks

    Comment by Marco | August 24, 2010 | Reply

  20. I am trying to create a webpart using peopleeditor, but i cannot see peopleeditor being a part of Microsoft.sharepoint.webcontrols, what am i missing. How can i make it available. Please help!!

    Comment by mydhili | September 7, 2010 | Reply

  21. Have you added a reference to the Microsoft.SharePoint.dll in your web part?
    Karine

    Comment by Karine Bosch | September 7, 2010 | Reply

  22. I have only one word to say.

    Awesome!!!!!

    Comment by varun | October 18, 2010 | Reply

  23. […] Here is an overview of the PeoplePicker control for SharePoint: https://karinebosch.wordpress.com/sharepoint-controls/peopleeditor-control/ […]

    Pingback by Browse the Active Directory in Silverlight | DeveloperQuestion.com | November 3, 2010 | Reply

  24. Thank you very much! This is awesome article!

    Comment by Nikolay | November 17, 2010 | Reply

  25. Thanks for the tip on this useful control! I’m deveolping a visual webpart (for Sharepoint) and I’m a bit unsure where the code:

    private PeopleEditor peopleEditor;
    private void EnsureChildControls()
    {
    peopleEditor = new PeopleEditor();
    peopleEditor.AutoPostBack = true;

    Panel1.Controls.Add(peopleEditor);
    }

    should reside (among otherthings).

    No handler is specified for any event triggering the postback so I’m wondering how to catch it.

    I would be thankfull for any tips.

    Comment by Gregory | November 19, 2010 | Reply

    • Some feedback on my travails:

      It is possible to add the PeopleEditor control to a Visual Webpart via the Design View for the .ascx file. It disappears but remains in the Source and seems to works fine when deployed.

      The code in post 2 didn’t work for me. The hashtable object was never instantiated for some reason.

      PickerEntity pickerEntity = (PickerEntity) PeopleEditor1.ResolvedEntities[0];
      OwnerID.Text = pickerEntity.EntityData[“AccountName”].ToString();

      worked fine for me though. You can always iterate the pickerEntity collection to find out what your keys are. Mine were different :O

      Comment by Gregory | November 20, 2010 | Reply

  26. How can I use this on a SharePoint 2010 contact list?

    Comment by Tom | December 16, 2010 | Reply

  27. Hi Tom,
    Can you please provide some more details? Are you talking about a standard contact list? Or are you creating your own list definition?
    Karine

    Comment by Karine Bosch | December 17, 2010 | Reply

  28. I’d like to use a stndard contact list. That way I could populate the “NewForm” with either information from AD or enter it manually. The TagPreFix in your example is for MOSS and I’m using 2010. I was thinking it might have something to do with the PeopleEditor calss.

    Comment by Tom | December 17, 2010 | Reply

  29. Hi Tom, if you have a list and the source for your PeopleEditor is the AD, why not simply add a column with the “user” column type?

    Comment by darkroastjava | December 17, 2010 | Reply

  30. Hi Tom,
    I was going to suggest the same thing as darkroastjava.
    The tag prefix is indeed for MOSS, but the PeopleEditor still works the same way in SharePoint 2010. Change the directive as follows by changing the version of the assembly:

    Karine

    Comment by Karine Bosch | December 17, 2010 | Reply

  31. oeps, xml is gone. Change the directive between the tags as follows:
    Register TagPrefix=”spuc” Namespace=”Microsoft.SharePoint.WebControls”
    Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”
    Karine

    Comment by Karine Bosch | December 17, 2010 | Reply

  32. Well that added the user but I’d like to populate the other fields but that’s a start, it gets the control on the page.

    Comment by Tom | December 17, 2010 | Reply

  33. oh I see! You want the user to select a user and then let it populate the other fields with properties from AD?
    In that case you will need to develop a custom form with some code behind. In that case I can advise you to create a new content type that inherits from the Contact list. You can find more details on how to proceed with a content type with custom form here: https://karinebosch.wordpress.com/walkthroughs/creating-a-custom-list-definition-based-on-a-generic-list-using-a-custom-content-type/
    You can develop a custom list definition based on the custom content type but it is not necessary.
    Karine

    Comment by Karine Bosch | December 17, 2010 | Reply

  34. Yep that exactly right. I’ll check out that post.
    Thanks

    Comment by Tom | December 17, 2010 | Reply

  35. The sample does not apply to a contact list but it can easily be achieved. Please let me know if you need additional help.
    Karine

    Comment by Karine Bosch | December 17, 2010 | Reply

  36. Hi, does anybody know if the following is possible: When I click on the Browse button I would like to be presentet with all users and groups automatically(I don’t want to enter username). Is it possible to search by some other property than username?

    Thanks in advance

    Comment by Zarko | December 29, 2010 | Reply

  37. Hi Zarko,
    The fact that you are not presented with the complete list of users and groups is to avoid performance problems when the control loads.
    For your second question, if you want to be able to search on other user profile properties, you will have to develop your own custom field inheriting from the Microsoft.SharePoint.WebControls.PeopleEditor control. You can find a number of samples on the web.
    Karine

    Comment by Karine Bosch | December 29, 2010 | Reply

  38. that helps a lot.thks!

    Comment by townway | January 4, 2011 | Reply

  39. Hi Karine,

    Did you eventually find a way to make AllowEmpty=”false” work ?

    Comment by Rahul Vartak | March 4, 2011 | Reply

  40. there is a people picker control and a list(dataview webpart) opened in spd2007.A parameter is created for people picker control in dataviewwebpart. how to filter the list based on username filled in peoplepicker control.

    Comment by Athulya | March 25, 2011 | Reply

  41. Hi Karine,

    Can I use peopleeditor control on an aspx page outside of sharepoint context. Fox example by setting the site property of the control?

    Comment by Radhika | May 14, 2011 | Reply

  42. Hi Radhika,
    Ik don’t think you can use the peopleeditor control outside the SharePoint context, I’m afraid it will not work.
    Kind regards,

    Comment by Karine Bosch | May 15, 2011 | Reply

  43. Thanks Karine for your reply. Just one more thing, can we update the selectionset with say just a custom list. For example, I need to display a group of users from the database and not display users from the Active Directory. Can we do that?
    I greatly appreciate your help.

    Comment by Radhika | May 17, 2011 | Reply

  44. Hi Radhika,
    If you want to do something like that, you will have to create your own custom people picker. Unfortunately I have no url to point you to.
    You can always post your question on the SharePoint forum where you have more chance to have your question answered.
    Kind regards,

    Comment by Karine Bosch | May 17, 2011 | Reply

    • Thank You.

      Comment by Radhika | May 18, 2011 | Reply

  45. Hi Radhika, I have recently created something like that and followed these links:

    http://efreedom.com/Question/1-1378661/Customize-MOSS-People-Picker-PeopleEditor-Control

    http://igorinnet.blogspot.com/2007/10/customizing-entityeditorwithpicker.html

    http://sppeopleactive.codeplex.com/

    Or, I can emeil you some code if you send me your address

    Regards

    Comment by Zarko | May 18, 2011 | Reply

  46. How do I make the control look like the one in the screenshot at the top?

    When I use it, I just end up with two buttons floating in the middle of the screen. There is no border around the inner text box. If I try to set a borderwidth, I just end up with a border around the whole thing (buttons and all). I still can’t see the text box.

    I can’t figure out how to se the border on the inner textbox.

    Thanks,
    rob

    Comment by RDuncan | June 10, 2011 | Reply

  47. Hi Duncan,
    That’s weird. The way I present it, is standard behaviour, no borders to set. Are you using SharePoint 2007 or SharePoint 2010?
    Karine

    Comment by Karine Bosch | June 14, 2011 | Reply

    • SharePoint 2010.

      I should add for clarity that the textbox is there, I just can’t see it. I can click on it and type a name, or see the name if I choose one. But a new user would have no idea there is a field there to click on.

      Rob

      Comment by Rob | June 14, 2011 | Reply

  48. Hi Rob,
    I just tried it out with SharePoint 2010, and I have the same behavior as explained in my blog post. Are you using the control from within an application page or web part? Can you please send me your code at karinebosch at hotmail dot com?
    Karine

    Comment by Karine Bosch | June 15, 2011 | Reply

  49. I want to assign multiple groups to “SharePointGroup” property, does anyone has idea on how to do this?

    Comment by Anna | July 2, 2011 | Reply

  50. that’s i am looking for
    thank you so much

    Comment by luhuiya | July 9, 2011 | Reply

  51. Thanks a lot.

    Comment by suresh tg | August 3, 2011 | Reply

  52. How can connect this People editor to a table in my local database which has all the users.As of now it gets it from the share point site where my app is running. I don’t want that. I heard this is definitely possible. Can anyone please help?

    Thanks.
    mimy

    Comment by mimy | August 16, 2011 | Reply

  53. Hi Mimy, I’m also convinced that this should be possible but I never tried it out. I think you will have a better chance to get a correct answer when you post this question to the MSDN SharePoint Developers forum.

    Comment by Karine Bosch | August 16, 2011 | Reply

  54. Thanks Karine. Will do that for sure.

    Comment by mimy | August 16, 2011 | Reply

  55. […] till exempel, namn på personen som kör koden. Det finns olika beskrivningar om hur man gör det. Allmänt, och mer specifikt för webparts. Jag har även testat kod från boken Sharepoint 2010 as a […]

    Pingback by PeopleEditor med ifyllt värde « Sharepoint. Kunskap. Upptäckter på resan. | August 21, 2011 | Reply

  56. Great Article. How do I bind a people picker list to the people picker control on my custom webpart?

    Comment by Snehal H.Rana | September 2, 2011 | Reply

  57. Awesome article. Very helpful… Thanks much!

    Comment by reivaxsevy | September 20, 2011 | Reply

  58. Hi,

    I am using people editor in SharePoint workflow initiation form to resolve user name and then put that in text box.

    What I would like to do is once the user name resolves in people picker and goes to the text box after that clear out the people picker dialog before adding other user id.

    I am working on SharePoint designer.

    Any help would be appreciated.

    Thanks.

    Comment by Anjalee | September 21, 2011 | Reply

  59. hi,

    i am using the below code to input key and the get values for the resolved entities.

    PickerEntity entity = new PickerEntity();
    entity.Key = “c”;
    entity = PeopleEditor1.ValidateEntity(entity);// it is false when the input key is having more than one result.

    if (PeopleEditor1.ResolvedEntities.Count > 0)
    {
    PickerEntity selectedEntity = (PickerEntity)PeopleEditor1.ResolvedEntities[0];
    Label1.Text = (string)selectedEntity.EntityData[“Email”];
    }

    but, my requirement to fetch all the resolved results in the picker dialog ( for example,if the key is “john”and the resolved result is having “john mathew” and “john” then entity = PeopleEditor1.ValidateEntity(entity);// is false but i have 2 results! ). we can get the result if entity = PeopleEditor1.ValidateEntity(entity);// is true. so how to achieve.

    Comment by Chethan Prakash | September 23, 2011 | Reply

  60. Hi Karine,

    I’m using PeopleEditor in a WebPart exactly the way you described it (SP2010). All I do is putting the following lines in CreateChildControls:

    peopleEditor = new PeopleEditor();
    peopleEditor.AutoPostBack = true;
    peopleEditor.ID = “PeopleEditor1”;
    peopleEditor.AllowEmpty = false;
    peopleEditor.MultiSelect = false;
    Panel1.Controls.Add(peopleEditor);

    PeopleEditor is rendered as expected but when I type in a name (name is resolved e. g. in Site Collection Permissions People Picker) and click the check names button the name isn’t resolved/not underlined. When opnening the search dialog via the book button and searching for the name the account is found. But after selecting and confirming with ok it is not displayed in the PeopleEditor.

    Do you have any idea what could cause this behaviour?

    Regards

    Daniel

    Comment by Daniel Zientek | October 14, 2011 | Reply

  61. Daniel,
    To be honest, I have no idea. This is the internal working of the control and I never had problems with it. Perhaps it’s a good idea to post this problem on the MSDN forum, you will have more chance on a helpful answer.
    Karine

    Comment by Karine Bosch | October 14, 2011 | Reply

  62. Really Nice Article ! Thanks..

    Comment by rishi ghai | October 20, 2011 | Reply

  63. Hi Karine,

    Actually i want to provide the sorting option in PickerDialog. Can you please help me out. Actually i have requirement like: When i search the sharepoint group name in dialog then all the users from this group should be listed (by default it gives group name only).

    Any idea about it.

    Comment by Hemendra | November 11, 2011 | Reply

  64. Hemendra,
    Ik think you will have to customize the PeoplePicker. Here is a good blog post on how to customize the EntityEditorWithPicker: http://igorinnet.blogspot.com/2007/10/customizing-entityeditorwithpicker.html

    Comment by Karine Bosch | November 13, 2011 | Reply

  65. HI Karine,

    I have already checked this link but i have two issue here.

    1. How can i replace this custom picker with existing out of box people picker. I am creating event receiver for this.

    2. How can i implement search, which can get user from AD as well as i could filter the user based on department.

    Please give me some guideline on both problems

    Comment by Hemendra | November 14, 2011 | Reply

  66. Karine
    am adding a people editor control in a dropdown selected index change. The control appears in the page, but when i enter a user, the name will not get resolved also throws an error “The target ‘ctl00$m$g_7af74cde_8682_4c1c_ab4f_79f6715d35b0$ctl00$Person’ for the callback could not be found or did not implement ICallbackEventHandler” . You have any idea how to resolve this issue ? Please help

    Comment by Dia John | November 15, 2011 | Reply

  67. Hi!
    I have a people picker control on aspx page. I am using a Form (It is really a div) having people picker control and submit button. What I need is to resolve user’s name before submission of data on click of submit button

    What problem I am facing is the name get resolved when the calling function on submit button get completed
    But I want to resolve name before it exit the custom JavaScript function on button click

    Please help me if there is any possibility

    Comment by Anurag | December 11, 2011 | Reply

  68. Hi,

    I have added the control in my ascx file and it works fine, except that… I am getting “There was an error in the callback.” message when I click on ‘check names’ option. anyone encountered / resolved this problem ?

    adnan

    Comment by Adnan Shamim | December 22, 2011 | Reply

  69. Resolved🙂
    here is what my declaration looks like in the ascx control
    ========

    ============

    and the page_load method in the code behind is like
    ============
    PeopleEditor1.AllowEmpty = false;
    PeopleEditor1.MultiSelect = false;
    PeopleEditor1.Visible = true;
    PeopleEditor1.ValidatorEnabled = true;
    ===========

    just had to enable validator thats it.

    Thanks a lot for this post Karine!

    regards,
    adnan shamim

    Comment by Adnan Shamim | December 22, 2011 | Reply

  70. Hi Karine, How can I get the ResolvedEntries after postback.
    I have a Button in my custom webpart and a peoplepicker too.
    After clicking button the page is getting postback and the entries in People Picker gone.
    How can I save the entries over postbacks.?

    Comment by Mohan | January 9, 2012 | Reply

  71. held me a lot

    Comment by Devendra | January 10, 2012 | Reply

  72. Very helpful! Thank you.

    Comment by Adam Roberts (@Strawsnake) | January 13, 2012 | Reply

  73. Perfect, you saved me time, I appreciate that!

    Comment by Samuel Sabel | January 23, 2012 | Reply

  74. When I use the below lines in my aspx , I get Null reference exception. Am I missing anything ? Please help.

    Comment by Kailas | February 24, 2012 | Reply

  75. Hi,
    I want to validate a user account from the code, without pressing on the Check Names button. Something like that:
    PeopleEditor pe = new PeopleEditor();
    pe.CommaSeparatedAccounts = “”;
    pe.Validate();
    ArrayList ar = pe.ResolvedEntities;
    Of course when I run this code, ar is empty. What else should be done?

    Thanks.

    Comment by Viktor Amkhinich | March 1, 2012 | Reply

  76. Correction:
    pe.CommaSeparatedAccounts =”some user name”;

    Comment by Viktor Amkhinich | March 1, 2012 | Reply

  77. Viktor, can you try out the code that is detailed in section “Retrieving User Profile”? And creating a new instance of a PeopleEditor will not work, you should work with an existing instance of the PeopleEditor control like in:
    PickerEntity selectedEntity = (PickerEntity)PeopleEditor1.ResolvedEntities[0];

    Comment by Karine Bosch | March 2, 2012 | Reply

  78. pe.Validate(); will validate what is inside and put red line under invalid entries.

    Comment by ofer gal | March 2, 2012 | Reply

  79. Karine, thanks for the answer. I came up with the following code:
    PeopleEditor pe = new PeopleEditor();
    pe.SelectionSet = “User,SecGroup”;
    PickerEntity entity = new PickerEntity();
    entity.Key = user.LoginName;
    entity = pe.ValidateEntity(entity);
    and this actually populates entity allright. I’m not sure exectly how it happens, and that worries me – may be in other circumstances it would not?

    Comment by Viktor amkhinich | March 2, 2012 | Reply

  80. Thanks for your suggestion Karine. I’m hoping someone can help me though.
    I’ve included the Register TagPrefix at the top of my web part page and I’m trying to insert the PeoplePicker control in to a standard web part.
    I’ve used the code you supplied with the aqua coloured div, however in SP Designer 2010, nothing appears other than a thin aqua coloured div and when loading the page, “Unknown server tag ‘spuc:PeopleEditor'” is displayed.
    Could you please tell me where I’m going wrong?

    Also, I’d really like to pass the chosen user as a filter value to a number of different XsltListViews on the web part. Is this possible?

    Comment by Chad | March 9, 2012 | Reply

    • Nevermind. I had a look at my master page and discovered that SharePoint.WebControls was already referenced with TagPrefix=”SharePoint”. So I just had to change ‘spuc’ to ‘SharePoint’.
      🙂

      Comment by Chad | March 9, 2012 | Reply

  81. Hi,
    how can I change the _display_ of PeopleEditor, if content is programmatically changed?
    eg. take 2 PeopleEditors PE1 and PE2 and a Button with Click-eventreceiver

    string s = PE1.Accounts[0].ToString();
    PickerEntity p = new PickerEntity() { Key = s };
    ArrayList a = new ArrayList() { PE2.ValidateEntity(p) };
    PE2.UpdateEntities(a);

    Now, if PE1 and PE2 are filled by UI (say with “UserA” and “UserB”) then clicking Button will correctly fill PE2 with “UserA”, but the page still shows “UserB” in PE2.
    Any suggestions?

    Comment by HansM | March 12, 2012 | Reply

  82. hi karine,

    i created a custom user field type and created a customize people picker. I added this field as a user column in a document library. I’m having trouble saving that data when my field allows multiple selections but this only happens when you are uploading latest document office type(docx,xlsx,pptx). but if the upload file does not match to the latest documents, it’s saving well. For what i know, the return type value of multiple selection should be spfielduservaluecollection right? is there restrictions on document library?

    Comment by davis | March 12, 2012 | Reply

  83. Hi Karine,
    I have another problem with my PeopleEditor. The page has 2 buttons, Save and Cancel, and if Save is pressed, users get validated, which can take some time. But if Cancel button is used, there’s no reason to go through validation. Still, it happens, and takes the same long time.
    In the Cancel Javascript event handler, I tried to set ValidatorEnabled to false, or to clear CommaSeparatedAccounts, or to set disabled attribute to disabled – nothing helps. Is there a way to do this?

    Thanks
    Viktor

    Comment by Viktor amkhinich | March 16, 2012 | Reply

  84. Can you try to set the CausesValidation property of your Cancel button to false? Validation shouldn’t occur this way.

    Comment by Karine Bosch | March 22, 2012 | Reply

    • I’ve tried, with the same result.

      Comment by Viktor amkhinich | March 27, 2012 | Reply

    • Finally, I got it. In the Cancel Javascript event handler, I put this:
      $(“div”).find(“[id*=’divEntityData’]”).empty();
      The idea is to give PeopleEditor no users to validate.

      Comment by Viktor Amkhinich | April 4, 2012 | Reply

  85. Hi Karine,
    I have another problem with the PE. In certain cases, I have to display PE disabled, just to inform the user. pe.Enabled=false; works fine, but only in IE. In FF, I still can type in. I added pe.AllowTypeIn=false; No difference in IE, in FF I cannot type in anymore, but still can delete.

    Any suggestions?

    Thanks

    Viktor

    Comment by Viktor Amkhinich | April 20, 2012 | Reply

  86. Hi I have a request for you.
    Hope I can get some help with your experience.
    It is related with user profile property and people picker field.
    User Profiles: I have added a new property called “Role” with string(Multi Value) — property type.
    Values in the ‘Role’ field are: Director, Valuer.
    In Manage user profiles: For some users I have allocated them as director and valuer, some are only valuers and some are only directors.
    ok now in SharePoint … I have created a people picker field in a list, now the requirement is, when the user select the browse icon next to the people picker field and search for the users.,then it should search and give only the people who have the value “Valuer’ in “Role” field( User Profiles).
    I am using Sharepoint 2010.

    Any ideas, really appreciatable.
    Struggling to get this done.
    Thanks

    Comment by Ven | May 31, 2012 | Reply

  87. Hi,

    I have an issue with People Editor. i have an people editor control in my custom web part. Based on the user id entered in the text box, i use to populate in the People Editor. This was working fine.

    Recently we upgraded our MOSS Server from SP2 to SP3 and Dec 2011 CU. People editor stopped population.
    Any body has any ideas to fix this issue?

    My Code below:

    using System;
    using System.Runtime.InteropServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Serialization;
    using System.Collections;

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Security;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.WebPartPages;

    namespace TestPicker
    {
    [Guid(“8c01ba24-e0d7-4388-b235-908f937efaa9”)]
    public class CustomPicker : System.Web.UI.WebControls.WebParts.WebPart
    {
    TextBox txt;
    PeopleEditor pe;
    Label l1;
    public CustomPicker()
    {
    }

    protected override void CreateChildControls()
    {
    base.CreateChildControls();
    Button b1 = new Button();
    b1.Text = “Populate”;
    b1.Click += new EventHandler(b1_Click);
    txt = new TextBox();

    pe = new PeopleEditor();
    pe.SelectionSet = “User”;
    pe.AutoPostBack = false;
    pe.Enabled = true;
    pe.Visible = true;
    pe.ValidatorEnabled = true;
    pe.MultiSelect = false;
    pe.AllowEmpty = false;
    pe.PlaceButtonsUnderEntityEditor = true;
    this.Controls.Add(txt);
    this.Controls.Add(b1);
    this.Controls.Add(pe);
    l1 = new Label();
    this.Controls.Add(l1);
    }

    void b1_Click(object sender, EventArgs e)
    {
    try
    {
    string value = txt.Text;
    ArrayList _ArrayPeople = new ArrayList();
    PickerEntity peEntity = new PickerEntity();
    peEntity.Key = value;
    peEntity = pe.ValidateEntity(peEntity);
    _ArrayPeople.Add(peEntity);
    pe.UpdateEntities(_ArrayPeople);
    }
    catch (Exception ex)
    {
    this.Page.Response.Write(ex.Message);
    }
    }
    }
    }

    Comment by Gireesh | June 14, 2012 | Reply

  88. Hi Karine,
    I am using your PeopleEditor control in my SP2007 application. we have two domains domain A and B.
    Is there any possibility to filter users from only domain A using this control.

    Thanks.

    Comment by Chamilas | July 9, 2012 | Reply

    • You could create a custom PeopleEditor that inherits from the SharePoint one. In this custom PeopleEditor you can add the necessary logic to pick users from a different domain.

      Comment by Karine Bosch | July 13, 2012 | Reply

  89. Hello,

    Thank you for this great post. I also have a question: when I search for a user through the “Browse” button, I get the response immediately but when I use “Check Names” it takes between 30 to 60s to return a result. Do you have any idea about what may be the cause?

    Thanks!

    Comment by Nick | July 13, 2012 | Reply

  90. HI karine,

    Thank you for this great post. i am new to the sharepoint.. I am using your PeopleEditor control in my SP2010 application pages.this page is loading the people editor control focus is not showing ..please help me .how to fix focus on the peopleEditor control.

    Comment by viswanadham | August 8, 2012 | Reply

  91. I like this post, very useful for me

    Comment by oracl3r | August 15, 2012 | Reply

  92. Why I am not getting red line when user does not match

    Comment by Manjunath T | August 23, 2012 | Reply

  93. wow!!!! Excellent articale

    Comment by john! | August 24, 2012 | Reply

  94. I have issue with the people editor control.
    I am using People Editor control on custom aspx page on MOSS 2007.

    First case ->
    When I submit the page without using people editor’s check name button, the collection ResolvedEntities contains the item for user.

    Second case ->
    I enter user name in people editor textbox and click check name button, it gets validated at client side as expected. Then I submit the form and check in the code behind page the ResolvedEntities collection is empty (count is zero).
    And also the people editor textbox is filled with some long xml message. What is wrong in second case?
    Below is my code in aspx:

    And below code in button click event handler:
    foreach (PickerEntity item in peUser.ResolvedEntities)
    {
    userID = item.Key;
    username = item.DisplayText;
    //Only one to read as MultiSelect attribute of People Editor is set to false
    break;
    }

    Please help.

    Comment by Prashant | October 23, 2012 | Reply

  95. further to my above post, I found that the issue happens with IE 9. There is no issue with IE 8 and Chrome browser.
    Is it known issue and is there any fix available?

    Comment by Prashant | October 23, 2012 | Reply

  96. HI Karine,

    May be I dont understand the programing with PeopleEditor control well. I want to get the value cahng event of this control. I want to take up the value and once validated, need to populate the Email, Phone no details for the user from User profile (AD). I saw a property OnValueChangedClientScript . Is this the way to do it ? no other events possible ? Could you please guide me?

    This is very critical too..

    Thanks in advance..

    Regards,
    Nimisha

    Comment by Nimisha | November 3, 2012 | Reply

  97. Hi Karine,
    I have a people picker and i assign a sharepoint group on page load.
    Now when i click the Addressbook icon i can see my group but the its not sorted by display name.
    if i will not assign a sharepoint group to picker the result is sorted out.Can this be sorted?

    Thanks,
    Louie

    Comment by louie | November 23, 2012 | Reply

  98. […] to use Sharepoint PeoplePicler control in your sharepoint solutions.If not here is a perfect blog https://karinebosch.wordpress.com/sharepoint-controls/peopleeditor-control/ i found while i was struggling. As it says we can bind either, User, SPGroup or SPSecurityGroup. […]

    Pingback by Bind DistributionLists(DL) with Sharepoint Peoplepicker « My SharePoint Experience | January 10, 2013 | Reply

  99. Hi Karine,

    I cannot use people picker as i need to use only sharepoint.webcontrols.userfield as it not of type basefieldcontrol. i need to use only create custom userfield only then i can update it back to the list as it has its internal name. can you tell me how to work with userfield in general except for MSDN there is no other help. i have placed my code here and which gives object reference not set error at UpdateFieldValueInItem

    UserField userField = (UserField)field.FieldRenderingControl; //spfield from the list
    userField.ID = “fld_” + field.Id;
    userField.ControlMode = SPControlMode.New;
    userField.ListId = splist.ID;
    userField.FieldName = field.InternalName;
    userField.RenderContext = SPContext.GetContext(HttpContext.Current, splist.DefaultView.ID, splist.ID, spWeb);
    SPFieldUserValue spfielduserValue = new SPFieldUserValue(spWeb, defaultValue[field]);
    userField.ItemFieldValue = spfielduserValue;
    userField.UpdateFieldValueInItem();
    AddControl(ctrlchkbox, labelText, userField) //adding the control to the page

    Thanks in advance
    Smitha

    Comment by smitha | January 22, 2013 | Reply

  100. This is a really good tip particularly to those new
    to the blogosphere. Short but very accurate info… Many thanks for sharing this one.

    A must read article!

    Comment by o use of seo for businesses | March 9, 2013 | Reply

  101. […] PeopleEditor Control « Karine Bosch’s Blog […]

    Pingback by Resources: SharePoint Development,Programming And PowerShell | lionadi | March 18, 2013 | Reply

  102. Hi sir, how to access the error message of people picker in code behind and display people picker error message in other location on the page normally it is displaying down the control and how to give our own error message to it

    Comment by shiva | May 4, 2013 | Reply

  103. Hello there! I simply would like to offer you a big thumbs
    up for your great information you’ve got here on this post. I will be coming back to your website for more soon.

    Comment by gigi lelo | May 6, 2013 | Reply

  104. hard to find this type of concise explanation on how to implement this control. Thank you for putting this together!

    Comment by Rick Jenkins | July 31, 2013 | Reply

  105. Thank you for anothber magnificent article. Where else could anyone
    get that kind of innformation iin such an ideal manner of writing?
    I have a presentation subsequent week, and I am at the look
    for such info.

    Comment by vasos de plasticos | September 11, 2013 | Reply

  106. No pensaba leer un post asi por estos lares pero he quedado
    gratamente agradecido esta vez

    Comment by Alejandro | October 8, 2013 | Reply

  107. Hi Karine,
    just a quick question: how many OUs can be assigned to a PeoplePicker? Or in other words: how man OUs can a PeoplePicker query to retrieve a member?
    Regards,
    Oliver

    Comment by Oliver Wirkus (@OWirkus) | November 7, 2013 | Reply

  108. Hii..
    I have a sharepoint custom webpart which contains People editor and a Assign Button.when I enter a wrong id and without click on check names proceed to click on Assign Button its shows an error “This entry is not found. Click for more actions.” and does not disapper.

    Please suggest me if you have any solution.

    Comment by Tarun | March 13, 2014 | Reply

  109. Thank you Karine.

    Comment by Miryam | April 2, 2014 | Reply

  110. […] More info on PeopleEditor you can visit Karine Bosch’s site […]

    Pingback by About PeopleEditor — Amirul Kamil's | June 26, 2014 | Reply

  111. Hi ….

    when i click on search button all user names are not displaying….

    could you please tell me the complete code ?

    Comment by Akul | December 26, 2014 | Reply

  112. Hi,
    could you please tell me how can I make it work in edit mode (datasheet view mode in 2010 sharepoint), because, when I click on the field, browse button do not appear (sharepoint 2013) and the same issue I have in sharepoint 2010, I mean that do not appear drop down list with possible values.
    Thank you a lot in advance

    Comment by Sergey | February 11, 2015 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: