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)
-
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...
-
One of our client wanted to show Employee Directory and our first suggestion was to build custom SPFx which will fetch data from Azure AD or...
-
Recently I was working on sending mail using smtp server where I stuck on below error: IIS/SMTP - emails are stuck in mailroot/Queue ...
No comments:
Post a Comment