Share via

SPItemEventProperties Class

Contains information about list item events.

Inheritance Hierarchy


Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online


<SerializableAttribute> _
<SubsetCallableTypeAttribute> _
Public NotInheritable Class SPItemEventProperties _
    Inherits SPEventPropertiesBase _
    Implements IDisposable
Dim instance As SPItemEventProperties
public sealed class SPItemEventProperties : SPEventPropertiesBase, 


The SPItemEventProperties class holds information about an item event, including fixed properties of the event such as event type, user name, and URL; it also includes Before and After properties of the list item for which the event is triggered when properties are available. For After events, the definitions of Before and After properties are straightforward: Before properties refer to settings that existed before the event occurred, and After properties refer to the settings that exist after the event has occurred. For Before events, however, Before properties refer to current item settings before the event occurs, while After properties refer to settings the item will have after the event occurs.


The following code example uses the SPItemEventProperties class to limit the number of items that can be added to a list.

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.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also


SPItemEventProperties Members

Microsoft.SharePoint Namespace