My SharePoint Blog

Blogs On SharePoint Technologies


Search Site


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


Recent posts

Recent comments

Tags

None

    Categories


    Disclaimer

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

    © Copyright 2009

    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 (11) | Post RSSRSS comment feed

    Comments

    Add comment


     

    biuquote
    • Comment
    • Preview
    Loading