Wednesday 28 May 2008

Use PeopleEditor (People Picker) in SharePoint Custom application development

Use PeopleEditor (People Picker) in SharePoint Custom App Dev

How to add the PeopleEditor (People Picker) control to your custom application development (ASPX, user controls, web parts, etc.)

The control we are interested in is the Microsoft.SharePoint.WebControls.PeopleEditor control.

First, we need to add a reference to the Namespace containing our control:

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


Next, add the PeopleEditor control to your page:

<wssawc:PeopleEditor
AllowEmpty="false"
ValidatorEnabled="true"
id="userPicker"
runat="server"
ShowCreateButtonInActiveDirectoryAccountCreationMode="true"
SelectionSet="User" />


Next, add an object on the server to work with the control:


using Microsoft.SharePoint.WebControls; //add a reference to Microsoft.SharePoint.dll if needed

public class MyPageName : Page
{
protected PeopleEditor userPicker;

}


Now, add your code needed to retrieve the entities:

public void btnSave_Click(object sender, System.EventArgs e)
{
….
PickerEntity pe = (PickerEntity)userPicker.Entities[0]; //gets first user in list
string username = pe.Description;

}

Notes:
The Description property will return the full account name (e.g. domain\username)
The DisplayText property will return the resolved name in the editor control (e.g. First Last)

----------------- Have A Nice Time !!! --------------------

3 comments:

Unknown said...

Sharepoint allows tasks to be saved on a web server that can be utilized by employees from any location, enabling for real-time cooperation. Tight safety actions are set so that only certain individuals can accessibility these information. Customers can also create their own individual storage information which cannot be utilized by anyone but them. The smooth Sharepoint interface guarantees that information are not combined or lost and that the right individuals have accessibility the information they need.

Custom Application Development India

Unknown said...

Interesting blog. It gives a lot of useful information.Thank you for sharing this.
Mobile Application development

[=Amit] Chugh said...

Thanks Elite...