To Remove Attached event receiver on feature deactivation use following example of code:
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
try
{
if (properties != null)
{
SPWeb spWeb = properties.Feature.Parent as SPWeb;
if (spWeb != null)
{
#region M1 List
SPList M1List = spWeb.Lists.TryGetList("M1List");
if (M1List != null)
{
SPEventReceiverDefinitionCollection oSPEventReceiverDefinitionCollection = M1List.EventReceivers;
System.Collections.Generic.List<SPEventReceiverDefinition> oRecieversToDelete = new System.Collections.Generic.List<SPEventReceiverDefinition>();
foreach (SPEventReceiverDefinition oReciever in oSPEventReceiverDefinitionCollection)
{
if (oReciever != null && oReciever.Assembly.Equals(System.Reflection.Assembly.GetExecutingAssembly().FullName))
{
oRecieversToDelete.Add(oReciever);
}
}
foreach (SPEventReceiverDefinition oSPEventReceiverDefinition in oRecieversToDelete)
{
oSPEventReceiverDefinition.Delete();
}
M1List.Update();
}
#endregion
}
}
}
catch (Exception ex)
{
throw ex;
}
}
For Feature Activation Code Sample Click Here
Subscribe to:
Post Comments (Atom)
What is the Use of X and Y Properties in Power Apps SharePoint List Form?
If you've spent any time customizing SharePoint List Forms using Power Apps, you've likely come across the X and Y properties ...
-
In last blog we learn how can we enable footer on SharePoint Online Modern Communication site. If you have not gone through that you can use...
-
Code Review :- General 1. Remove the commented code 2. Variable name should not be contain "_". 3. Query should be in separat...
-
Issue : Recently, we had a requirement to sync the calendar between shared mailbox outlook and SharePoint Calendar list. We have created 2 f...
No comments:
Post a Comment