One of the sorely missing pieces in the Silverlight toolbox for SharePoint developers is a people picker control. There is a control that SharePoint provides, which you can use in a web part or custom layouts page (the PeopleEditor class). Silverlight code though all executes on the client side, so there isn’t an out of the box solution for this. I really needed this functionality on a recent project and ended up finding a fairly simple way to build just such a thing. Here’s a screenshot of my admittedly No-UI-Talent picker control, implemented as a popup in Silverlight:
The key to making this thing work is a nice little web service that SharePoint ships out of the box called the People web service. In this case I used method called SearchPrincipals to take the text that was typed in the Search box and find a list of possible matches. In my simple case I only needed to find one and one only user. However I could have also asked for groups, distribution lists, or SharePoint security groups. You could also implement your own version of the type-in control by letting someone type in a name and then calling the ResolvePrincipals method on the web service. Here are a few of the implementation details that you might find interesting:
//get info on the current host
string curUrl = HtmlPage.Document.DocumentUri.AbsoluteUri.ToString();
//get the host name; note that this assumes the user has rights to the root site
//site collection; that may not be true in your scenario
Uri curUri = new Uri(curUrl);
HostName = curUri.Scheme + "://" + curUri.Host + ":" + curUri.Port.ToString();
//use the host name property to configure the request against the site in
//which the control is hosted
PeopleWS.PeopleSoapClient ps = new PeopleWS.PeopleSoapClient();
new System.ServiceModel.EndpointAddress(HostName + "/_vti_bin/People.asmx");
Actually that’s probably the only particularly interesting part. I’m attaching the code for the user control to this posting. Unfortunately for a variety of reasons I can’t include the entire project, but hopefully this post and the control code itself will be enough to get you pretty far down the road should you need something like this.
The attached SL_PeoplePicker.zip don't have the definition for the PeopleWS webservice definition.It would be really helpful if you caould attach the code snippet for the same.
Many thanks in advance.
As is stated in the post above: "The key to making this thing work is a nice little web service that SharePoint ships out of the box called the People web service."
I'm curious why you didn't use the SharePoint Silverlight Client Object Model instead of the service.
Very useful article.
Thanks for the post this is what i also need in my current project.
I am new to silverlight could you please post the complete solution if have or mail me
Thanks in advance