Skip to main content

Custom People Picker (Editor) in SharePoint 2010





[Modified:11 Oct 2010] Now you can find the source code for this example in CodePlex

The out-of-the-box SharePoint people picker allows users to select users, SharePoint groups, Distribution Lists & Security groups. Users may accidentally add large AD groups to SharePoint groups and send notifications to hundreds of people. The administrator may want more control over the security of the people picker control. In some scenario the administrator may want to restrict the user to only select ‘users’ or ‘SharePoint Groups’. This can be achieved by creating a custom people picker control which inherits from SharePoint people editor. In below example, we are going to explore creation of custom people picker control, replace the OOTB people editor control, provide a people picker settings page in central administration and create menu to access the settings page in Central Administration.

1. Create custom people picker
For creating a custom control (which inherits from SharePoint PeopleEditor) we need to create Empty SharePoint Project in Visual Studio 2010.




Figure 1: Create a new project – Empty SharePoint Project in Visual Studio 2010

Once pressing OK on the above screen, select the SharePoint site where you want to deploy the custom people picker. Select deploy as a farm solution and click finish.

Figure 2: SharePoint customization wizard – enter site address where you want to deploy and choose deploy as farm solution

Once the empty SharePoint project is created, create a class which will be our custom people picker. This class must inherit from Microsoft.SharePoint.WebControls.PeopleEditor class. Now override the OnLoad method. In this method we will implement the settings selected by the admin in CA. These settings are selection of admin (web/site admin) and the restrictions on the selection. That is whether to allow selection of users, SP groups, security groups or distribution lists.

Figure 3: Custom people picker class implementation

Now that we have created a custom people picker, we have to instruct SharePoint to use our custom people picker instead of OOTB people editor. For this we have to create a feature receiver which will do modifications to the web.config file. For letting SharePoint know which control to use instead of OOTB controls we have to add a new tag in tagmapping section in web.config file. For doing so we have to write the code in feature activated event.

Figure 4: Code in feature activated event to add tag mapping entries in web.config

Now the event receiver class must be added to the feature xml file.

Figure 5: Feature xml file where we have to mention the event receiver class.

2. Deploy application page (people picker settings) to Central Administration

Once the custom people picker project is deployed successfully to the site collection, we have to create a people picker settings page and deploy the same to Central Administration. For this purpose we have to create a new empty SharePoint project in the solution. While creating the project, we have to mention the CA site path so that Visual Studio can automatically activate the feature.
Now create a new SharePoint mapped folder. For t his right click on the project, point to Add, and then click on SharePoint Mapped Folder. On the dialog box, select {SharePointRoot}\TEMPLATE\ADMIN folder and then click OK.

Figure 6: Add ADMIN mapped folder.

Once the ADMIN mapped folder is added, right click on the ADMIN node, point to Add, and then click New Item. On the dialog box, select Application Page, give a nice name and click Add.
You will notice your application page is added to Layouts folder. Drag and drop newly created application page to ADMIN folder. Now you can delete the Layouts folder.

Figure 7: Drag and drop application page to ADMIN folder and delete Layouts folder

In the application page, we will provide admin user to select web application, web application settings, and privileges for common user and admin user.


Figure 8: People picker admin settings page in Central Administration


Once the application page is ready, we have to provide navigation in CA. For this, add a new item to the project and select Module.

Figure 9: For adding navigation item to CA, add a Module to the existing project.

When a module is added, VS automatically adds Elements.xml and a .txt file. Delete the .txt file. In the elements.xml file, delete the existing content and add the following XML. In here, we will create a link in Timer Jobs section of Monitoring in CA. The custom action groups can be found at http://msdn.microsoft.com/en-us/library/bb802730.aspx

Figure 10: Adding custom action groups in elements.xml file

Figure 11: Application page menu can be found in Central Administration

Summary
When the admin creates new settings in the People picker admin page in Central Administration, his settings are persisted for a particular web application. The custom people picker will then read from the persisted data and act accordingly.


- Vighnesh Bendre

Comments

Ravindher said…
hi vignesh,
Great post.
Here i have one problem that i want add one dropdown to picker dialog in the dropdown say like i have web and site when i click web and search i want to display the users who are in the web application. if i select site and search i have to display the site collection users only.
Waiting for u r reply
Hemendra said…
HI Vighnesh,

First of all, that is really very good post. Thanks for posting it. Actually i have got the similar kind of requirement and i am having an small issue. I want to modify the pickerdialog as well. I mean Either add an dropdown control for sorting the users ORELSE if i find the sharpoint group then all users from this particular group should be displayed in listbox so i can add them one by one.
As you are using "base.DialogTitle = "Custom People Editor";" line in your code to change the title but i want to know if there is any way to redirect to our custom page in similar way.
Any help / direction much be appreciated
Vighnesh said…
Hi Hemendra, I have sent u a PM. Please chk...
Jignesh said…
Hi,
I want to create PeoplePicker as Client Side User Control i.e.(.ascx) file. using JavaScript and HTML markup only. Control should run Client side NOT Server side.
Is it possible??

Popular posts from this blog

Create list view - Conditional Formatting in SharePoint Designer 2010

In this example, we are going to format a column based on certain condition. Here I already have a list called Projects. I also have workflow associated with it. So whenever I create a new item in the list, workflow status column shows ‘In Progress’. Subsequently when the workflow in completed, the workflow status column shows ‘Completed’. For demonstration purpose, I will set the background color of workflow status column to yellow when the status is ‘In Progress’ and to green when the status is ‘Completed’. In SharePoint Designer open the site on which you are working. Click on ‘Lists and Libraries’ link. Choose the ‘Projects’ list. In SharePoint Designer Navigation, choose ‘Lists and Libraries’. In the list settings page, click on ‘New’ in ‘Views’ section. Provide appropriate name for the view and click OK. After choosing list, click on ‘New’ in the Views section. Give appropriate name to the list. Now click on any column, then in the ribbon, click on List View Tools-&g

SharePoint 2013 (SP 15) - Creating Custom Lists

As I am exploring SharePoint 2013, I found out that there are lot of things that are new and there are lot of thing that are old but presented in a different manner as compared to SharePoint 2010. For example, Site Actions was on the top left corner in SP 2010. But in SP 15 (SharePoint 2013) we dont have ‘Site Actions’ button. But instead we have a settings icon which is placed at top right corner. When you click on the settings icon select Add an App. This will basically allow you to add custom lists, documents libraries etc. Add an App is basically the same as More Options in SharePoint 2010. From now on custom lists & libraries will be called apps. Just like in Apple store or Android store you can develop apps for SharePoint and sell it. You can find more information here: http://officepreview.microsoft.com/en-us/store/apps-for-sharepoint-FX102804987.aspx When you click on Add an App you will be navigated to a different scree which will display different opti

Working with large xml files in c# .net

Working with large (huge) xml files is always a pain in the … The reason? These files can’t be loaded in to memory. On my desktop, where I have 2 gigs memory, I can’t open the file in even notepad. I was presented with a challenge recently to manipulate one such large xml file. The xml file was of 550+ MB. I know many would say I have seen bigger xml files than this. But the heart of the matter is if I can’t open 550+ MB file in notepad or in xmldocument in c#, then I can’t open any file bigger than this. And hence the logic to play with these files would remain same. The scenario: We have an xml file from which we want to remove a single node without removing its children. In the below sample xml fragment, the node has to be removed. The children nodes, must then be attached to ( node’s parent) node. One Two 100.22 GoodDay 3 4 Five 200.09 Cra