If you are thinking about globally changing the behavior of SharePoint People Picker with custom validation logic, without going through the hassle of modifying every single page in SharePoint, then you are in the right place.
SharePoint application pages and user controls with a people picker declaratively uses the Microsoft.SharePoint.WebControls.PeopleEditor Web Control and sets the control’s properties to change its validation logic that meets specific requirements.
If you want to display only users that are members of a site collection or to customize the search filter for active directory, you might want to use STSADM to set people picker settings in a higher scope than setting the properties of an instance.
However, STSADM will not completely meet your needs, as you might have some random reason to have a custom logic:
You might want to restrict users of certain members of some special domain group from getting resolved.
You might want to make sure that the resolved users are in fact active (not disabled) account in active directory;
You might even want to resolve users from a data source that the people picker cannot reach OOTB.
I knew in my head that there is an elegant way to customize the validation logic of the SharePoint people picker and have the change propagates across a SharePoint Web Application. So, I kept asking my best friend Google, “globally replace a web control using the Web.Config”, “and please answer my prayers” (J Am telling you I couldn’t find a hint, maybe I should switch to Windows Live Search). And, then boom! Jonas Nilsson, one of my favorite mentors from Bamboo Solutions mentioned changing something in the Web.Config to redirect the declarative usage of a control to a new control. Yes! A couple phone later, I found out it was just two words, “Tag Mapping” (stupid me! I couldn’t even remember that?).
For whatever reason if you need to implement custom validation logic and have the effect to be global, overriding the PeopleEditor SharePoint control accordingly, and using Tag Mapping to redirect all declarative usage of the SharePoint People Picker control is inevitable. Tag Mapping (a new feature in ASP.NET 2.0) defines a collection of tag types to be remapped to other tag types at compile time. According to Nickil Kothari’s blog, It was originally invented as part of the Web Part framework so as to allow the ASP.NET WebPartManager to be mapped to the derived SharePoint WebPartManager implementation without having to change individual pages.
Long story short, you should just need to do the following:
1. Create a new class deriving Microsoft.SharePoint.WebControls.PeopleEditor
2. Override ValidateEntity(PickerEntity entity)
- 3. Sign your assembly with a Strong Name
- 4. Install assembly into the GAC
- 5. Put tag mapping entry in the Web.Config
- 6. Add your Assembly in the assemblies section in the Web.Config (Thanks René) UPDATE 04-22-2010