zoukankan      html  css  js  c++  java
  • Remove an Event Receiver in SharePoint

    Everyone and their brother shows you the quick and dirty method on how to add an event receiver to a list.  Not many people show you how to remove them (Not even some of the Microsoft Press books…)  There are 2 ways.. if you have the GUID of your event receiver, instantiate an instance of  an SPEventReceiverDefintion object with that guid and then delete it.  Else, here’s the long way: (I’m going under the assumption that you’re a good MOSS/WSS programmer and using Features to deploy your event handler…)

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties){

     using (SPWeb web = (SPWeb)properties.Feature.Parent){

    SPDocumentLibrary proposals = (SPDocumentLibrary)web.Lists["test"];
    SPEventReceiverDefinitionCollection erdc = proposals.EventReceivers;
    SPEventReceiverDefinition erd = null;
    bool found = false;

    for (int i = 0; i < erdc.Count; ++i){
    erd = erdc[i];
    if (erd.Assembly == asmName && erd.Type == SPEventReceiverType.ItemAdded){
    found = true;
    break;}
    }
    if (found)
    erd.Delete();
    }
    }

  • 相关阅读:
    Python装饰器理解(新手)
    vue项目随笔
    ajax 请求数据传到后台为空字符
    关于document.body.scrollTop 的谷歌,火狐浏览器兼容问题
    Nginx 反向代理解决浏览器跨域问题
    SpringBoot maven build a new demo
    UI收集
    git
    编译
    网络2
  • 原文地址:https://www.cnblogs.com/icedog/p/1779080.html
Copyright © 2011-2022 走看看