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
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)
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");
}