提供用于捕获事件发生到项的方法。永远不会实例化此类。
继承层次结构
System.Object
Microsoft.SharePoint.SPEventReceiverBase
Microsoft.SharePoint.SPItemEventReceiver
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Class SPItemEventReceiver _
Inherits SPEventReceiverBase
用法
Dim instance As SPItemEventReceiver
public class SPItemEventReceiver : SPEventReceiverBase
备注
此类无法实例化,但项事件接收器类中的自定义事件处理程序必须从此类派生并重写其处理的事件类型的方法。
如果项目被移动,它作为一项已被删除并添加相同的方式进行处理。
Before和After的属性并保证 post 事件上的文档,但Before属性不可用于发送事件的列表项。
示例
下面的代码示例使用此类附件添加到列表时,将项目添加到指定的通知列表。
using System;
using Microsoft.SharePoint;
namespace Example_Namespace
{
public class Class_Name : SPItemEventReceiver
{
public override void ItemAttachmentAdded(SPItemEventProperties properties)
{
using(SPSite oSiteCollectionEvent = new SPSite(properties.SiteId))
{
SPWeb oSiteEvent = oSiteCollectionEvent.OpenWeb(properties.RelativeWebUrl);
SPListItemCollection oItemsEvent = oSiteEvent.Lists[properties.ListTitle].Items;
}
using(SPSite oSiteCollection = new SPSite("http://Top_Site"))
{
SPWeb oWebsite = oSiteCollection.OpenWeb("Website_Name");
SPList oList = oWebsite.Lists["Announcements"];
SPListItemCollection collListItems = oList.Items;
SPListItem oItem = collListItems.Add();
oItem["Title"] = properties.UserDisplayName + " added an attachment to " + oItemsEvent[properties.ListItemId].Title + " in list " + properties.ListTitle + " at " + properties.WebUrl;
oItem.Update();
}
}
}
}
Imports System
Imports Microsoft.SharePoint
Namespace Example_Namespace
Public Class Class_Name
Inherits SPItemEventReceiver
Public Overrides Sub ItemAttachmentAdded(ByVal properties As SPItemEventProperties)
Using oSiteCollectionEvent As New SPSite(properties.SiteId)
Dim oSiteEvent As SPWeb = oSiteCollectionEvent.OpenWeb(properties.RelativeWebUrl)
Dim oItemsEvent As SPListItemCollection = oSiteEvent.Lists(properties.ListTitle).Items
End Using
Using oSiteCollection As New SPSite("http://Top_Site")
Dim oWebsite As SPWeb = oSiteCollection.OpenWeb("Website_Name")
Dim oList As SPList = oWebsite.Lists("Announcements")
Dim collListItems As SPListItemCollection = oList.Items
Dim oItem As SPListItem = collListItems.Add()
oItem("Title") = properties.UserDisplayName & " added an attachment to " & oItemsEvent(properties.ListItemId).Title & " in list " & properties.ListTitle & " at " & properties.WebUrl
oItem.Update()
End Using
End Sub
End Class
End Namespace
备注
某些对象实现IDisposable接口,并必须避免后不再需要保留这些对象在内存中。好的编码做法有关的信息,请参阅Disposing Objects。
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。