SPItemEventProperties 类

包含有关列表项事件信息。

继承层次结构

System.Object
  Microsoft.SharePoint.SPEventPropertiesBase
    Microsoft.SharePoint.SPItemEventProperties

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
<SerializableAttribute> _
Public NotInheritable Class SPItemEventProperties _
    Inherits SPEventPropertiesBase _
    Implements IDisposable
用法
Dim instance As SPItemEventProperties
[SerializableAttribute]
public sealed class SPItemEventProperties : SPEventPropertiesBase, 
    IDisposable

备注

SPItemEventProperties类,其中包含有关项目事件,包括事件类型、 用户名称和 URL ; 例如事件固定的属性的信息它还包括Before和After属性的属性可用时为其触发该事件的列表项。对于After事件, Before和After属性的定义不变得非常简单: Before属性引用发生之前发生此事件的设置和After属性是指存在事件之后发生的设置。对于Before事件,但是, Before属性引用当前的项目设置之前发生的事件,而After属性引用项目将具有该事件发生后的设置。

示例

下面的代码示例使用SPItemEventProperties类来限制可以添加到列表的项目数。

using System;
using Microsoft.SharePoint;

namespace Example_Namespace
{
    public class Class_Name : SPItemEventReceiver
    {
        public override void ItemAdding(SPItemEventProperties properties)
        {
            using(SPWeb oWebsite = new SPSite(properties.SiteId).OpenWeb(properties.RelativeWebUrl))
            { 
                SPListItemCollection collItems = oWebsite.Lists[properties.ListTitle].Items;

                if (collItems.Count > 150)
                {
                    properties.Cancel = true;
                    properties.ErrorMessage = "Adding items to this list is not supported because it already contains " + 
                        colItems.Count.ToString() + " items.";
                }
            }
        }
    }
}
Imports System
Imports Microsoft.SharePoint

Namespace Example_Namespace
    Public Class Class_Name
        Inherits SPItemEventReceiver
        Public Overrides Sub ItemAdding(ByVal properties As SPItemEventProperties)
            Using oWebsite As SPWeb = New SPSite(properties.SiteId).OpenWeb(properties.RelativeWebUrl)
                Dim collItems As SPListItemCollection = oWebsite.Lists(properties.ListTitle).Items

                If collItems.Count > 150 Then
                    properties.Cancel = True
                    properties.ErrorMessage = "Adding items to this list is not supported because it already contains " & colItems.Count.ToString() & " items."
                End If
            End Using
        End Sub
    End Class
End Namespace

备注

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

SPItemEventProperties 成员

Microsoft.SharePoint 命名空间