About Me

Having 12 years experience in Microsoft technologies.Since more than 7 years working in SharePoint technologies. Expert in providing consultation for SharePoint projects. Hands on with development and administration.

Sunday 6 October 2013

How to delete SharePoint event receivers on feature deactivating method.


public override void FeatureDeactivating(SPFeatureReceiverProperties properties)

        {

            SPWeb web = properties.Feature.Parent as SPWeb;
            try
            {

             SPList list = web.Lists.TryGetList("List name"); 

               if (list != null)
                 {
                  SPEventReceiverDefinition receiverDefinition = null; 

                  for (int i = list.EventReceivers.Count - 1; i >= 0; i--)
                            {
                                receiverDefinition = list.EventReceivers[i];
 
                                receiverDefinition.Delete();
                            }
                        }
            }

            catch (Exception ex)
            {

                PortalLog.LogString("Exception - {0}  -- {1} -- {2}", "XXXXXX", ex.Message, ex.StackTrace);

            }
        }

2 comments: