Working with the PeopleEditor in ASP.NET

This article has code snippets used to work with People editor in ASP.NET and SharePoint;

Adding the control
Using Sharepoint TAG
 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
 
<SharePoint:PeopleEditor runat="server" ID="peopleEditor"  
       
AutoPostBack="true" AllowEmpty="false" SelectionSet="User,SecGroup,SPGroup"  
       
BorderWidth="1" PlaceButtonsUnderEntityEditor="false" Rows="1" /> 
Using C#
 
 

PeopleEditor pplEditor = new PeopleEditor();

            pplEditor.ValidatorEnabled = true;

            Panel1.Controls.Add(pplEditor);

 
Getting values from control
 

for (int i = 0; i < pplEditor.ResolvedEntities.Count; i++)

{

PickerEntity picker = (PickerEntity)pplEditor.ResolvedEntities[i];

Hashtable hstEntityData = picker.EntityData;

string accountName = Convert.ToString(hstEntityData["AccountName"]);

      string emailID = Convert.ToString(hstEntityData["Email"]);

}

Setting initial value

//Load peopleEditor values from Aprovadores 

            if (oItemAtivo["Aprovador_x0028_es_x0029_"] != null)

            {

                string users = string.Empty;

 

                SPFieldUserValueCollection userCol = new SPFieldUserValueCollection(oWeb, oItemAtivo["Aprovador_x0028_es_x0029_"].ToString());

 

                foreach (SPFieldUserValue usrItm in userCol)

                {

                    users += usrItm.User.ToString() + ",";

                }

 

                peopApp.CommaSeparatedAccounts = users.Remove(users.LastIndexOf(","), 1);

            }

 
 
Related Links

Back To Top