Selecting a user in a SharePoint form: Sample of using the PeopleEditor

I needed to select a user while building a form in SharePoint. I hadn't done that before so I searched the web and looked in some books I have and found what I needed, almost...

The samples I found didn't quite work, when I moved the code into my own page and browsed to it SharePoint gave a generic error. There was no indication of what was wrong so I created a minimal test page and modified it until it worked, I think the problem was lack of Import statement for Microsoft.SharePoint.WebControls.

To help others who are facing the same problem I publish the minimal application page below. Take the code and paste it in an ASPX file (e.g. pe.aspx), then save the file into C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS. Finally browse to https://yourservername/_layouts/pe.aspx to check if the control renders properly.

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" %>

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

<asp:Content ID="PageTitle" runat="server" contentplaceholderid="PlaceHolderPageTitle" >
Browser title
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" runat="server" contentplaceholderid="PlaceHolderPageTitleInTitleArea" >
SharePoint Page Title
</asp:Content>

<asp:Content ID="Main" runat="server" contentplaceholderid="PlaceHolderMain" >
<SharePoint:PeopleEditor
ID="peApprover"
runat="server"
AllowEmpty="false"
SelectionSet="User"
MultiSelect="false"
AllowTypeIn="true"
PlaceButtonsUnderEntityEditor="false"
/>
</asp:Content>

Detailed information about properties and methods on the PeopleEditor control can be found at https://msdn2.microsoft.com/en-us/library/ms468579.aspx. There you can read all about how you can customize the control to fit your needs.

Comments