Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Could someone help and explain how I can attach an event handler on a custom content type or a particular list?

Currently, when I deploy my event handler as a feature and activate the feature, it is applied to all the lists.

Thanks,

Matrich

share|improve this question
add comment

2 Answers 2

Use the Receivers element in the element manifest with ListTemplateId for lists or add the Receivers element as a sub element to the XmlDocument element in the Content Type (read more here)

share|improve this answer
add comment

adding event receiver to document library /list programatically. here i am mentioning for Document Library.

     SPDocumentLibrary docLib = web.Lists.TryGetList("Temp Resources") as SPDocumentLibrary;
        docLib.EnableVersioning = true;
        docLib.EnableMinorVersions = false;
        docLib.Update();
        if (docLib != null)
        {
            docLib.EventReceivers.Add(SPEventReceiverType.ItemUpdating, Assembly.GetExecutingAssembly().FullName, "Event Receiver Class Name");
            docLib.EventReceivers.Add(SPEventReceiverType.WorkflowCompleted, Assembly.GetExecutingAssembly().FullName, "Event Receiver Class Name");
        }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.