Wednesday 3 February 2010

Adding event receivers to custom list templates

Problem: wanted to create a list template and with some event receivers.

Normally I use the SharePoint Solution Generator to dump the list templates. So I have created a list using GUI and added some event receivers and used the SSG to generate the template. (I got my 4 aspx files and the schema.xml)




When you check the schema, you can see that the Event receivers are correctly added under the <Receivers> tag. So I have used a feature to deploy the list template and created a list using deployed template. List was created successfully with all the fields and views, but unfortunately my Event receivers were missing. I doubled checked and tried again, got the same results.

While googleing, found an article which you can use a separate Elements file to bind the Event receivers to particular list type.

I have use the same method and its working with the list template. In addition to that it adds the event receivers to list which are already created through my custom template.

Note that you need to correctly match the ListTemplateOwner and ListTemplateId





So, basically this registers the event receivers based on the list type and you can use this to add event receivers to existing custom list by just creating a feature, rather than writing new codes.