您的位置:首页 > 其它

SharePoint【事件处理器】-- SPEventReceiver的一点总结

2013-02-21 08:50 344 查看
以下内容是对SPEventReceiver的一点总结

一、概述

五种事件处理器基类:

1、SPItemEventReceiver

2、SPListEventReceiver

3、SPEmailEventReceiver

4、SPWebEventReceiver

5、SPWorkflowEventReceiver

SPItemEventReceiver包含如下方法:

Name

Description

ContextEvent

This member is reserved for internal use and is not intended to be used directly from your code.

DisableEventFiring

Obsolete. Prevents events from being raised. (Inherited from SPEventReceiverBase.)

EnableEventFiring

Obsolete. Enables events to be raised. (Inherited from SPEventReceiverBase.)

Equals

(Inherited from Object.)

Finalize

(Inherited from Object.)

GetHashCode

(Inherited from Object.)

GetType

(Inherited from Object.)

ItemAdded

Handles the asynchronous event that occurs after an item is added.

ItemAdding

Handles the synchronous event that occurs before an item is added.

ItemAttachmentAdded

Handles the asynchronous event that occurs after an attachment is added to an item.

ItemAttachmentAdding

Handles the synchronous event that occurs before an attachment is added to an item.

ItemAttachmentDeleted

Handles the asynchronous event that occurs after an attachment is removed from an item.

ItemAttachmentDeleting

Handles the synchronous event that occurs before an attachment is removed from an item.

ItemCheckedIn

Handles the asynchronous event that occurs after an item is checked in.

ItemCheckedOut

Handles the asynchronous event that occurs after an item is checked out.

ItemCheckingIn

Handles the synchronous event that occurs before an item is checked in.

ItemCheckingOut

Handles the synchronous event that occurs before an item is checked out.

ItemDeleted

Handles the asynchronous event that occurs after an item is deleted.

ItemDeleting

Handles the synchronous event that occurs before an item is deleted.

ItemFileConverted

Handles the asynchronous event that occurs after a file in a document library is converted from one type to another.

ItemFileMoved

Handles the asynchronous event that occurs after a file is moved.

ItemFileMoving

Handles the synchronous event that occurs before a file is moved.

ItemUncheckedOut

Handles the asynchronous event that occurs after an item is unchecked out.

ItemUncheckingOut

Handles the synchronous event that occurs before an item checkout is discarded.

ItemUpdated

Handles the asynchronous event that occurs after an item is changed.

ItemUpdating

Handles the synchronous event that occurs before an item is changed.

ItemVersionDeleted

Occurs after an item or file version is deleted.

ItemVersionDeleting

Occurs when an item or file version is being deleted.

MemberwiseClone

(Inherited from Object.)

ToString

(Inherited from Object.)

  

SPItemEventProperties方法和属性说明
方法和属性说明
BeforeProperties获取事件发生前的数据
AfterProperties事件发生后的数据,AfterProperties类型是SPItemEventDataCollection,可以通过其ChangeedProperties属性在前处理事件中给列表赋值
AfterUrl事件发生后文件的URL
EventType事件类型
ListItem列表项对象
ListItemId列表项Id
ListTitle列表标题
CurrentUserId当前用户ID
UserDisplayName当前用户名
UserLoginName当前用户登录名
RelativeWebUrl站点的相对url
SiteId当前站点的ID
WebUrl当前站点的url
OpenWeb采用此方法打开当前的站点对象,站点对象打开之后需要用Dispose方法进行释放。或者用using
ReceiverData事件处理器关联的数据
Cancel释放取消事件的执行。
ErrorMessage事件取消时显示的错误消息
源文档 <http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver_methods.aspx>

每个方法都有一个SPItemEventProperties参数,包含很多关于提交记录的相关信息。

具体信息请参考MSDN文档 http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventproperties_members.aspx

二、结构分析(以SPItemEventReceiver为例):

View Code

public override void ItemUpdated(SPItemEventProperties properties)

{

this.EventFiringEnabled = false;

properties.ListItem["Title"] = "Title";

properties.ListItem.SystemUpdate();

this.EventFiringEnabled = true;

}


五、事件接收器,返回错误信息的时候,界面不友好;我们可以自己写一个错误页;

方法:layouts下新建一个error页面,接收错误信息并显示。

properties.Cancel = true;
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = "/_layouts/EventReceiverProject3/Error.aspx?error=" + SPHttpUtility.UrlKeyValueEncode("u are wrongs!");


转载:/article/5799259.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐