LinkedIn

Tuesday, December 10, 2013

Writing Event Handlers for a Specific Sharepoint 2010 List

When you register Event handlers get added to all the lists of that template. for eg: Lets take a common scenario. Lets say you will have at least 2 custom lists in your site List1, List2. Now you write an event handler that you want to trigger on operations on one list List1. But this event handler also gets attached to List2 without you intending for.
Solution:
            There are may solutions you may find for this. One and most straight forward is write a feature stapler. But again writing a stapler is not easy and takes a lot of time. Also it's one more feature added to your site.
            The second solution(not too obvious) also exists. Now if you are writing a feature you got to have a Elements.xml file(At least I have to have one). Here making some tweaks will solve your problem.
I have created a solution called GG.BlogsEventHandler. I have written Asynchronous receiver. Below is how my Elements.xml looks like.



Look carefully at line #4. Do you see any difference? By default you will have


where xx=template id of your list. Custom Lists have "301" . Instead of giving a template Id, I have given site relative Url of the List.

No comments:

Post a Comment