Ever wanted to borrow that cool AJAX like control in SharePoint 2007 (or WSS 3.0) that lets you pick and resolve users so that you can manage those users/groups and their permissions.

The control I'm talking about is PeopleEditor (aka People Picker) and there's not much documentation out there, and the examples are not very helpful.
At some point in time last year I decided to investigate this control and find out how to get resolved items out of it, as I needed to use it and abuse it for a component of a SharePoint solution at the time.
I got some questions recently about it, so I promised that I will post a very simple example on how to use it, so here it goes:
This web part in a very crude (not recommended) way filters out the groups with permissions on a Task list on the web and allows for adding/removing users through PeopleEditor control to groups selected through the dropdown control.

(Please note that this is just to show a proof of concept, do not use this web part as is in production)
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace PplEdtr
{
[Guid("4114de9b-ae5c-45a4-b1c0-b8e4abf4675e")]
public class PplEdtr : System.Web.UI.WebControls.WebParts.WebPart
{
public PplEdtr()
{
this.ExportMode = WebPartExportMode.All;
}
private Label dropDownListLabel;
private DropDownList dropDownList;
private PeopleEditor peopleEditor;
private Button buttonAddUser;
private Button buttonRemoveUser;
private SPList taskList;
private string html = null;
protected override void CreateChildControls()
{
base.CreateChildControls();
string groupName = null;
this.dropDownListLabel = new Label();
this.dropDownList = new DropDownList();
using (SPWeb web = SPContext.Current.Web)
{
taskList = web.Lists["Tasks"];
this.dropDownList.Items.Clear();
this.dropDownListLabel.Text = "Select the group where you want to add the desired user for the Task List: " + taskList.Title + " ";
foreach (SPRoleAssignment role in taskList.RoleAssignments)
{
bool isGroup = true;
try
{
SPGroup group = taskList.Lists.Web.Groups[role.Member.Name];
groupName = group.Name;
}
catch (Exception ex)
{
isGroup = false;
}
if (isGroup == true)
{
ListItem listItem = new ListItem();
listItem.Text = groupName;
listItem.Value = groupName;
this.dropDownList.Items.Add(listItem);
}
}
}
this.peopleEditor = new PeopleEditor();
this.Controls.Add(peopleEditor);
this.buttonRemoveUser = new Button();
this.buttonAddUser = new Button();
this.buttonAddUser.Text = "Add a User to the Selected Group";
this.buttonRemoveUser.Text = "Remove a User from the Selected Group";
this.buttonAddUser.Click += new EventHandler(buttonAddUser_Click);
this.buttonRemoveUser.Click += new EventHandler(buttonRemoveUser_Click);
this.Controls.Add(this.dropDownListLabel);
this.Controls.Add(this.dropDownList);
this.Controls.Add(this.buttonAddUser);
this.Controls.Add(this.buttonRemoveUser);
}
private void buttonAddUser_Click(object sender, EventArgs e)
{
foreach (PickerEntity entity in peopleEditor.ResolvedEntities)
{
if (entity.IsResolved == true)
{
try
{
SPGroup group = taskList.Lists.Web.Groups[dropDownList.SelectedItem.Value];
bool isPresent = false;
foreach (SPUser groupUser in group.Users)
{
if (groupUser.LoginName == entity.DisplayText)
isPresent = true;
}
if (isPresent == false)
{
group.AddUser(entity.DisplayText, null, null, null);
group.Update();
html = html + "<br>The selected User: " + entity.DisplayText + " has been added to the Group: " + group.Name + "</br>";
}
else
html = html + "<br>The selected User: " + entity.DisplayText + " already exists in the Group: " + group.Name + "</br>";
}
catch (Exception ex)
{
html = html + "<br>" + ex.Message + "</br>";
}
}
else
html = html + "<br>Entity " + entity.DisplayText + " is not resolved, please ensure it's resolved before you procede" + "</br>";
}
this.dropDownListLabel.Text = html;
}
private void buttonRemoveUser_Click(object sender, EventArgs e)
{
foreach (PickerEntity entity in peopleEditor.ResolvedEntities)
{
if (entity.IsResolved == true)
{
try
{
SPGroup group = taskList.Lists.Web.Groups[dropDownList.SelectedItem.Value];
bool isPresent = false;
foreach (SPUser groupUser in group.Users)
{
if (groupUser.LoginName == entity.DisplayText)
{
SPUser user = group.Users[entity.DisplayText];
isPresent = true;
group.RemoveUser(user);
group.Update();
html = html + "<br>The selected User: " + entity.DisplayText + " has been deleted from the Group: " + group.Name + "</br>";
}
}
if (isPresent == false)
html = html + "<br>The User: " + entity.DisplayText + " does not exist in the selected Group: " + group.Name + "</br>";
}
catch (Exception ex)
{
html = html + "<br>" + ex.Message + "</br>";
}
}
else
html = html + "<br>Entity " + entity.DisplayText + " is not resolved, please ensure it's resolved before you procede" + "</br>";
}
this.dropDownListLabel.Text = html;
}
}
}
You can download the source code here (http://dotnet.org.za/blogs/zlatan/PplEdtr.zip)
This was done (in a huge rush) using the following:
Visual Studio 2005
SharePoint 2007/WSS 3.0 SDK 1.3
Visual Studio Extensions for SharePoint 1.1