Thursday, January 16, 2014

Auto fill Piplepicker control

Some times we are facing problem to autofill user names and groups iin people picker editor in SP 2010. But in SP2013 it provides one control which allow auto fill user names or groupname.
<sharepoint:clientpeoplepicker allowmultipleentities="true" cssclass="ms-long ms-spellcheck-true" id="peoplePicker" principalaccounttype="User,SPGroup,SecGroup,DL" rows="1" runat="server" validationenabled="true" visiblesuggestions="3" > </sharepoint:clientpeoplepicker>
To allow All user and AD groups we need to set the property PrincipalAccountType="User,SPGroup,SecGroup,DL" to as given values .
To access data from the control below is the code set.
SPFieldUserValueCollection mailListUsers = new SPFieldUserValueCollection(); ArrayList resolvedEntities = peoplePicker.ResolvedEntities; foreach (PickerEntity entity in resolvedEntities) { string loginName = entity.Key; SPUser mailUser = compWeb.EnsureUser(loginName); SPFieldUserValue usertoadd = new SPFieldUserValue(compWeb, mailUser.ID, mailUser.LoginName); mailListUsers.Add(usertoadd); }