About Sharepoint EventHandler

Inside Sharepoint2010 读书笔记
 
1. 可设置after事件为同步执行,好处之一是ui不会滞后
在Receiver声明中加入:<Synchronization>Synchronous</Synchronization>

2. 即使在added事件中如果对当前条目做update,也可以并且应该禁止事件触发。在updated事件中则必须禁止事件触发,防止式循环
EventFiringEnabled

3. 做数据修改时,有个方法,可以防止生成新版本
properties.ListItem.UpdateOverwriteVersion();
4. 在adding事件中,beforeproperties是空的,因为这时数据还未写入list中。updating事件中beforeproperties中是item当前的值。在after事件中,properties.listitem可直接访问
5. 在ing事件做数据验证的时候,可以指定自定义的错误页面
properties.Cancel = true;
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = properties.Web.Site.Url + "/WingtipErrorPages/ListDeleting.aspx";

6. 可以用服务器对象模型来注册事件,可实现用声明方式无法完成的功能,比如可以给某一个item加事件或为contenttype加事件(在沙箱模式下不可用)。要注意不能多次注册,同时也要注意提供解除注册的方法,通常在Feature激活和反激活事件中做:

7. 可以指定自定义的数据给eventhandler,也许可实现一个类处理多个事件
 




原文地址:https://www.cnblogs.com/teamleader/p/2128124.html