sharepoint中eventhandler的ItemUpdated

sharepoint中eventhandler的ItemUpdated

 

 

最近在开发Sharepoint的EventHandler的时候发现一个问题,更新事件的接受处理程序的特殊性,要被调用很多次,会达不到我们想要的效果,需要用 this.DisableEventFiring();来关闭事件监听器,在写完更新事件的代码之后要用  this.EnableEventFiring();来开启事件监听器。这个我也是在网上找到的。


using
 System;
using  System.Collections.Generic;
using  System.Linq;
using  System.Text;
using  System.IO;
using  Microsoft.SharePoint;
using  Microsoft.SharePoint.Administration;

namespace  CorpTrendEventDemo
{
    
public   class  IitemList : SPItemEventReceiver
    {

        
public   override   void  ItemUpdated(SPItemEventProperties properties)
        {

                SPListItem item 
=  properties.ListItem;
                SPWeb web 
=  item.Web;
                SPSite site 
=  web.Site;



                
this .DisableEventFiring();
                //修改审批状态
                 item["_ModerationStatus"] = (int)SPModerationStatusType.Approved; 
                 item.Update();
               

                item.CopyTo(properties.WebUrl 
+   " / " + properties.OpenWeb().Lists[ " 未发布动态 " ].RootFolder.Url + " / " +  item.Name);
                item.Delete();
                
this .EnableEventFiring();

         
        }
    }
}

 

 

来源:http://www.cnblogs.com/virusswb/archive/2009/01/06/1370045.html

你可能感兴趣的:(SharePoint)