Declaring and Reading the SharePoint People Picker Values Programmatically.

Declaring the Sharepoint Custom People Picker and Reading the Value.

1. Copy and Paste the below code in your form to create the Sharepoint Custom People Picker Control in Visual Web part design page.

<SharePoint:PeopleEditor ID="pplEditor" CssClass="ms-long ms-spellcheck-true" runat="server" Rows="1" MultiSelect="false" PlaceButtonsUnderEntityEditor="false" Width="500" SelectionSet="User" />

2. Make it "true" the MultiSelect Option, if you want to select the Multiple Users from the Picker.

3. Use the below code snippet to Read the Value from the People Picker.

SPFieldUserValue userValues=new SPFieldUserValue();
userValues = GetSPUserValue(web, pplEditor);

Method used to Get the People Picker Values

 /*People Picker Control*/
        public SPFieldUserValue GetSPUserValue(SPWeb objSPWeb, PeopleEditor pplEditor)
        {
            try
            {
                SPFieldUserValue userValue = null;
                if (pplEditor.Entities.Count > 0)
                {
                    PickerEntity pplAssigned = (PickerEntity)pplEditor.Entities[0];
                    SPUser webUser = objSPWeb.EnsureUser(pplAssigned.Key);
                    userValue = new SPFieldUserValue(objSPWeb, webUser.ID, webUser.Name);
                }
                return userValue;
            }
            catch (Exception ex)
            {
                Common.LogErrorDetails("ContractRequest", Convert.ToString(MethodBase.GetCurrentMethod().Name), ex.Message);
                return null;
            }
        }


Hope this code will help.... :)

Comments

Popular posts from this blog

SharePoint 2013 Keyword Query (KQL) Content Class Property Restrictions

Filtering the Sharepoint List Taxonomy Column using Rest API

SharePoint CSOM to Create Folders and Sub Folders based on Excel Data