My SharePoint Blog

Blogs On SharePoint Technologies


Search Site


My SharePoint Blog recommends any of the following books...


Recent comments

Tags

Don't show

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    How to use the PeoplePicker in SharePoint

    I found this blog on how to do it.

    Here is the basic idea..

     

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using System.Drawing;
    public partial class _Default : System.Web.UI.Page
    {
        private PeopleEditor objEditor;
        protected void Page_Load(object sender, EventArgs e)
        {
            objEditor = new PeopleEditor();
            objEditor.AutoPostBack = true;
            objEditor.PlaceButtonsUnderEntityEditor = true;
            objEditor.ID = "pplEditor";
            objEditor.AllowEmpty = false;
            objEditor.SelectionSet = "User,SecGroup,SPGroup";
            objEditor.MultiSelect = false;
            Panel1.Controls.Add(objEditor);
        }
        private string GetAccountName()
        {
            string strAccountName = String.Empty;
            for (int i = 0; i < objEditor.ResolvedEntities.Count; i++)
            {
                PickerEntity objEntity = (PickerEntity)objEditor.ResolvedEntities[i];
                SPUserInfo objInfo = new SPUserInfo();
                objInfo.LoginName = objEntity.Key;
                strAccountName = objInfo.LoginName;
                // to return a sharepoint people group formatted string use...
                // strAccountName = objEntity.EntityData["SPUserID"].ToString() + ";#" + objEntity.DisplayText.ToString();
            }
            return strAccountName;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string strAccountName = GetAccountName();
            Label1.Text = "account name: " + strAccountName;
        }
    }


    Or via HTML:

    <SharePoint:PeopleEditor runat="server" ID="pplEditor"
            AutoPostBack="true" AllowEmpty="false" SelectionSet="User,SecGroup,SPGroup"
            BorderWidth="1" Width="200px" PlaceButtonsUnderEntityEditor="false" Rows="1" />

     

    For this code to work you must publish it to a SharePoint website. You cannot run it from the Visual Studio debugger. 

    Here is the MSDN class reference.


    Categories: SharePoint
    Posted by Kevin on Friday, July 20, 2007 3:07 PM
    Permalink | Comments (3) | Post RSSRSS comment feed

    Comments

    olyvia

    Monday, July 07, 2008 5:33 AM

    I have a problem with page postbacks and the PeopleEditor. I have created the following:
    - a standard web user control with a multiview with several views in it. Some linkbuttons are used for navigating between the views
    - one of the views has the People Editor displayed. I build this up via code
    - this user control is hosted within the Smart Part (v1.3) in a publishing MOSS site

    Problem: if a user adds a group or user in the PeopleEditor, the value will not be retained after 2 postbacks. So, if users start to navigate between the views, they PeopleEditor will be empty after two postbacks. I tried different combinations with the Viewstate and autopostback attributes, but no joy.
    Can you please suggest a solution?

    Steve

    Tuesday, July 22, 2008 10:33 AM

    Hi,

    I'm having trouble with the above piece of code. I'm actually inserting the value provided in the people picker control to a list field which is of type "People or Group".
    I'm getting error : Invalid data has been used to update the list item. The field you are trying to update may be read only.
    Regards,
    Steve

    srikanth

    Monday, August 25, 2008 5:24 PM

    Hi Kevin,

    I'm using pplEditor in one of my form which is meant for editing a list item retrieved from MOSS list. I want the pplEditor to pre-populate with value(user name).
    I'm having tough time in getting this work. Can you please let me know how to acheive the same.

    regards,
    srikanth

    Add comment


     

    [b][/b] - [i][/i] - [u][/u]- [quote][/quote]



    Live preview

    Thursday, December 04, 2008 5:46 PM