Provides methods for event receivers in the Microsoft SharePoint Foundation object model and serves as the base class for creating list items, lists, Webs, and sites.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
The SPEventReceiverBase class should not be instantiated but provides methods for receiver classes deriving from it that are listed in the Inheritance Hierarchy section. Override one of the derived classes below to create a custom event handler, and register the handler by using the SPEventReceiverDefinition class.
The following code example shows how to register a custom event receiver that traps the delete event on the Web site.
Dim webSite As SPWeb = New SPSite("http://localhost").OpenWeb() Dim newReceiver As SPEventReceiverDefinition = webSite.EventReceivers.Add() newReceiver.Class = "Receiver.Class1" newReceiver.Assembly = "Receiver, Version=22.214.171.124, Culture=neutral, PublicKeyToken =10b23036c9b36d6d" newReceiver.SequenceNumber = 3000 newReceiver.Type = SPEventReceiverType.SiteDeleting newReceiver.Update()
SPWeb oWebsite = new SPSite("http://localhost").OpenWeb(); SPEventReceiverDefinition newReceiver = oWebsite.EventReceivers.Add(); newReceiver.Class = "Receiver.Class1"; newReceiver.Assembly = "Receiver, Version=126.96.36.199, Culture=neutral, PublicKeyToken =10b23036c9b36d6d"; newReceiver.SequenceNumber = 3000; newReceiver.Type = SPEventReceiverType.SiteDeleting; newReceiver.Update(); oWebsite.Dispose();
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.