Wednesday, September 17, 2008

Using People Picker control in your Webpart

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls;

namespace PeoplePickerWebPart
{
public class TeamMemberPicker : System.Web.UI.WebControls.WebParts.WebPart
{
protected override void CreateChildControls()
{
try
{
PeopleEditor PeoplePickerControl = new PeopleEditor();
PeoplePickerControl.AllowEmpty = true;
PeoplePickerControl.AllowTypeIn = true;
PeoplePickerControl.BrowseButtonImageName = "browse";
PeoplePickerControl.BrowseButtonToolTip = "Pick an TeamMember";
PeoplePickerControl.CheckButtonImageName = "Validate user";
PeoplePickerControl.ErrorMessage = "No TeamMember Found";

this.Controls.Add(PeoplePickerControl);
base.CreateChildControls();
}
catch (Exception ex)
{
Literal _ErrorMessageLiteral = new Literal();
_ErrorMessageLiteral.Text = "Custom Error: " + ex.Message;

this.Controls.Clear();
this.Controls.Add(_ErrorMessageLiteral);
}
}
}
}
Articles:
http://dotnet.org.za/zlatan/archive/2008/04/21/using-peopleeditor-control-with-web-parts-in-sharepoint-2007-wss-3-0.aspx

2 comments:

Sai Krishna November 5, 2008 at 2:52 PM  

Sandeep,

With following statements in the your code, showing the browken image links of check names and browse images:

PeoplePickerControl.BrowseButtonImageName = "browse";
PeoplePickerControl.CheckButtonImageName = "Validate user";

Were you able to see normla text links in the place of image links?

Please let me know if anything need to be changed.

Sandeep K Nahta November 5, 2008 at 3:47 PM  

Yes it does work .. Also checkout the article with the bog.. that might help