Thursday, July 21, 2011

How to validate the users in sharepoint's peoplepicker controls

Here are the steps to include SharePoint people picker control.
Step1: Add the below people picker control in your sharepoint page(.aspx)

Step2: Add the below code to validate the users and stores the user information into SharePoint list.
string PeoplePickerValue=peoplepcikerID.CommaSeparatedAccounts;
if (!string.IsNullOrEmpty(PeoplePickerValue))
   {
       SPUser User1 = null;
       User1 = spDLRWeb.AllUsers[PeoplePickerValue];
       if (User1!= null)
          {
              //To add People Picker to the list items.
              // ”Title” is Single Line of text field.
             spListItem["Title"] = User1.Name; 
             //”Manager” is People Picker Field.
             spListItem["Manager"] = User1;
           }
    }
else{ return; }
In the above code, "CommaSeparatedAccounts" will return the valid users information only otherwise it will return null value.
Note: Now,PeoplePicker validations are implemented on server side. i will update how to validate the users in people control at client side soon..

No comments:

Post a Comment