Tuesday, September 15, 2015

SharePoint People Picker

There is a quite new control for me in development in SharePoint which is people editor and i usually name is as people picker. Below is how the people picker look like.



Below is the front end code for people editor.

<SharePoint:PeopleEditor
                            AllowEmpty="true"
                            ValidatorEnabled="true"
                            ID="peEngineer" Width="250px"
                            runat="server" MultiSelect="false"
                            ShowCreateButtonInActiveDirectoryAccountCreationMode="false"
                            SelectionSet="User" />


Below is the code behind for get the user name from

//for SharePoint people picker
                    ArrayList resolvedEntities = peEngineer.ResolvedEntities;
                    SPUser engineer = null;
                    string engineerName = string.Empty;
                    foreach (PickerEntity entity in resolvedEntities)
                    {
                        engineer = SharePointUtil.GetCurrentSharepoinSite().RootWeb.EnsureUser(entity.Key);
                        engineerName = engineer.LoginName;
                    }


After you get the name from the AD, now show how to bind the value to the people picker. You may trigger any action such as button click or page load to run below code so that able to bind data into the people picker.

peEngineer.CommaSeparatedAccounts = "i:0#.w|contoso\testid";

cs

No comments:

Post a Comment