Tuesday, September 21, 2010

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

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

Thursday, September 16, 2010

Can not navigate to the requested page while User Profile Synchronization is running. Please wait for the current Synchronization run to finish.

From: Manage Profile Service
Where: Application Management->Manage Service Applications->User Profile Service Application->Manage->Start Profile Synchronization
Can not navigate to the requested page while User Profile Synchronization is running. Please wait for the current Synchronization run to finish.

From: Manage Services on Server- User Profile Synchronization Service
Where: Application Management->Manage Services on Server->User Profile Synchronization Service->Start
Below error is thrown in the event viewer.

It seems that the service account used for running the ‘User Profile Synchronization Service’ is not part of local administrator. I read in other blogs that this service tries to access HKLM\SYSTEM\CurrentControlSet\Services\FIMSynchronizationService\Parameters registry key. So adding this service account to local administrator group in ‘Server Manager’ would solve the problem.

-Vighnesh Bendre

Error while activating feature - SharePoint 2010

Hi all,
While I was working on SharePoint 2010 recently I came across some issues. I am putting them across so that anyone facing the same issue may find solution easily.

Error occurred in deployment step 'Activate Features': Feature with Id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' is not installed in this farm, and cannot be added to this scope.

I was getting this error while ‘deploy’ing a feature from Visual Studio 2010. I searched the entire project for this GUID which is mentioned in the error. I did not find it anywhere. While troubleshooting, I opened the physical folder and opened ‘Feature1.feature’ file in notepad. This xml file was using the before mentioned GUID. I was not able to find it in VS 2010 :(

I copied the GUID mentioned in the ‘Feature1.feature’ file and pasted it in the Feature ID section in ‘Feature1.Template.xml’ file. This solved the problem. Why I thought to mention it is because the exception thrown is confusing. It does not tell you about the exact error.

-Vighnesh Bendre