Event Registrations

Register event handlers at the site or site collection level that you will use to implement filtering to respond to list item events.

The Receivers element specifies an event handler for list item events.

Elements

  Receivers

    Receiver

      Name

      Type

      SequenceNumber

      Assembly

      Class

      Data

Example

To register an event handler for list events, create a folder in \Template\Features to contain a Feature.xml file that specifies the scope and ID of the Feature, and an elements manifest file that the former file references.

The Feature.xml file that registers an event handler might look like the following.

Xml
<Feature 
  Scope="Web" 
  Title="Simple Updating Item Event Handler Registration" 
  Id="A6B8687A-3200-4b01-AD76-09E8D163FB9A" 
  xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>
  </ElementManifests>
</Feature>

The elements manifest file registers the event handler assembly and associates it with a list type, which the following example specifies to be announcement lists (104).

Xml
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers 
    ListTemplateOwner="ADDABAAA-1111-2222-3333-111111111111" 
    ListTemplateId="104">
    <Receiver>
      <Name>SimpleUpdateEvent</Name>
      <Type>ItemUpdating</Type>
      <SequenceNumber>10000</SequenceNumber>
      <Assembly>SimpleUpdateEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=10b23036c9b36d6d</Assembly>
      <Class>MS.Samples.SimpleItemUpdateHandler</Class>
      <Data></Data>
    </Receiver>
  </Receivers>
</Elements>

The .cs file for the event handler can use the Windows SharePoint Services object model to respond to events. For information about using the object model to create custom event handlers, see Event Fundamentals.

The following example defines the content of an error message to display when users attempt to modify items in a list.

C#
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace MS.Samples
{
    public class SimpleItemUpdateHandler : SPItemEventReceiver
    {
        public override void ItemUpdating(SPItemEventProperties properties)
        {
            properties.Cancel = true;
            properties.ErrorMessage = "Updating data is not supported.";
        }
    }
}

See Also



Community Content

austegard
Filter element documentation is missing
Where is the documentation for the Filter element?

GhostPoster
Filter element does not exist
The <Filter> element was never implemented in Office 12 and it does not do anything. In the future, this SDK example will not include representation of this element.
Tags :

Thomas_Östreich
ListTemplateOwner works not correctly?
I Have a Problem with to Different Features and a identy TemplateType
Feature1 ID="EF286210-5F80-404d-8E91-856A19168DDE" TemplateType="11005" (Template Hidden=True)
Feature2 ID="43A18B61-2352-4365-B91E-9736F88F4E99" TemplateType="11005" (Template Hidden=True)

I'm deploy the Receiver with id of feature2 , and i look in the EventReceiver Collection to List on Template from Feature1 -> EventReceiver Attached (Bad)
List on Template from Feature2 -> EventReceiver Attached (correctly)


<Receivers ListTemplateOwner="43A18B61-2352-4365-B91E-9736F88F4E99" ListTemplateId="11001">
<Receiver>....

Page view tracker