Thursday, August 16, 2012

Clean Simple Event Handlers

One of the projects I worked on was using SharePoint 2007.One of the subsites contiains many lists and each one requires some calculation and validation whenever you add or update or delete an item.One of the reasons we made that was the fact SharePoint 2007 doesn't support cascading.A developer worked on the project and used a third party tool to add cascading fields for SharePoint lists and he also used a custom solution he downloaded to attach event handlers for each list he choose.

Well I prefer to avoid these things so I made my own event handlers in SPItemEventReciever and deploy it as a feature.

Just for time saving and because almost all the lists in that site require custom code otherwise it is better to follow a different approach so a different handler is called foreach list instead of one handler for all lists.I will talk about using specific handler foreach list in another article later.

After I deployed my custom SPItemEventReciever feature the surprise was whatever my code is correct or has some errors other things happen even that I can debug my code?!!

So I decided to uninstall all the custom solutions and the Third Party tool for cascading.

I remembered that I used U2U tool (windows application) in the past to explore handlers for the SharePoint List and Remove it.

Unfortunatily I found that tool doesn't exist any more on the web and I don't have time to search for the U2U I copied on another machine 2 years ago.

I searched the web and after around one hour I found a similar tool in codeplex:

Using that tool I found there was some custom handlers still attached for the site lists so I removed them.

After that (at last) my custom reciever class handlers handled the site lists events successfully.  

Why making organization chart while it does exist already?!

A rule any SharePoint developer must follow:
You must check existing OOB Web Parts and Features before creating custom work and waste very long time on something that already exist.

In SharePoint 2007 making a custom Organization Chart was the correct choice because there was no OOB Organization Chart but now you shouldn't go for that immediatly since it does exist in SharePoint 2010:

However like any other component in SharePoint it needs some configuration.But unlike many other components some of these configurations should be done first in the Active Directoy.For example to make several employees belongs to the same department (as colleagues) under one manager you should go to the properties for that user in the Active Directory and set in the Organization tab who is the manager for that user and what is the department he works in.

If this OOB Organization chart does not cover the customer requirements then you will need to use a custom Organization Chart webpart like the following:

Good Luck!

SharePoint 2010 Profile Synchronization Never let it stop you !

In the past as any developer new to SharePoint 2010 I was facing many problems with profile Synchronization.But the most thing I was afarid of is to be stuck for example if the service hang on Starting what should I do? But afterwards it never stopped me again.

Remember there are two different cases:
  1. You used correct steps from the begining
  2. You didn't know about one of the steps and you are already stuck
I will explain case 1 then case 2 and if you face any problems afterward ask me just never let it stop you.

Case 1:

Before doing anything there is a secret which is : You must have one of the Microsoft Hotfixes installed which you can install it from the following link:

It could be already added in one of the SharePoint 2010 new updates but you must make sure you have it installed anyway.

First if the User Profile Service Application doesn't exist already Create it by going to :
Central Admin > Application Management > Manage Application Services
On the Robbin Click new then select the User Profile Service

If it does exist just make sure the user of the Application Pool is the SharePoint Service Account

Since you have the Profile Service Application set and ready
Go to Start Menu > Administration Tools > Services
There are two well known FIM services:

Both should have the account set to the same user you used on the User Profile Application Pool above.
foreach service after you set the account set it to start automaticaly.

Go to : Central Admin > System Settings > Services on the server
First start the User Profile Service (If it is not already started) after it is started start the User Profile Synchronization Service.

You will need to select the User Profile Service Application which you have created or corrected before.

You will also be asked to a user name and password which are the User Name and password you used when creating the User Profile Service Application.

After you Click OK make sure to wait 10 minutes at least (I know this is the most boring part).

After 10 minutes passed refresh the page to see if the User Profile Synchronization have started successfully(If not check Case 2).

Run the iisreset command.
So now go to Manage Service Applications page again and click on the User Profile Service Application link and the User Profile Configurations Page will appear.

Before you can create a Synchronization Connection you need to make sure the SharePoint Services account have replicate directory changes rights.

To do that on the Domain Controller Server go to Administrative Tools then Active Directory Users And Computers.Right click your domain like and select Delegate Control.

Go through the Delegation Of Control wizard steps.Add the SharePoint Services User.Choose to create a custom task.

Click Next until you reach the permissions page.
Select the replicating directory changes then click Next then Click Finish.

Return to the Central Administration Page.In the Synchronization Section Click Configure Synchronization Connection then click New Connection.

Write a name for your connection and make sure the type is set to Active Directory.Use the SharePoint Services Account user name and password.Leave "Auto Discover Domain Controller" selected and enter your forest name (

Click Populate Container.When the whole Active Directory Containers appear make sure to select only the users OU you need to read from (far away better) then Click OK.

You should see your connection created in the Connections Window.

Go to the Synchronization Section again and click on Start Profile Synchronization then select Start Full Synchronization then Click OK.

After few seconds refresh the Profile Configurations Page so you see if the Synchronizing is running by having the status showing Synchronizing.

When it is finished you should see Idle instead of  Synchronizing.

Now if you see the number of synchronized people have changed that means you made it successfully!

Case 2:

If you are stuck already for example You have the User Profile Synchronization showing starting all the time don't panic.Because unlike SharePonit 2007 you can go to Manage Service Applications Page and delete the existing User Profile Service Application instance because you can create a new one again so you are not stuck anymore and to confirm that go to the Manage Service Applications Page again and you will find the User Profile Synchronization stopped at last (As soon as you delete the User Profile Serivce Application).
So you can start with the correct steps above to have your user profile synchronization works.

If you are facing any problem related to this subject please add a comment below and I will reply to you as soon as possible.

Helpful and cheap Book about User Profile & My Site configurations.

Good Luck...