Wednesday, 17 October 2012

No Exact Match Found (SharePoint's PeoplePicker control)

While testing an application page I'd just developed which had a few people picker controls, I noticed that I could select users, SharePoint groups and security groups (as desired), but when I clicked on the validate button, I got the message:

No exact match was found. Click the item(s) that did not resolve for more options.

If I ignored the validation error and clicked Save, the code behind worked fine, and the selected users and groups where process accordingly.





So why was I getting a validation error for groups that exist? Because I was setting the SelectionSet in code during the Page_Load event, the SelectionSet property was being over written when the control was loaded later in the page lifecycle (see: ASP.NET Page Life Cycle Overview)

ppAdmin.SelectionSet = String.Format("{0},{1},{2}", 
PeopleEditor.AccountType.User, 
PeopleEditor.AccountType.SecGroup, 
PeopleEditor.AccountType.SPGroup);

When I added the property to the declaration, presto, it worked properly!

<SharePoint:PeopleEditor runat="server" ID="ppAdmin" 
MultiSelect="True" Height="75" AllowEmpty="False" 
DialogWidth="495" Width="495" AllowTypeIn="True" 
SelectionSet="User,SecGroup,SPGroup" />