次の方法で共有


SPEventReceiverBase Class

Base class that provides methods for event receivers in the Windows SharePoint Services object model. This class is never instantiated.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.SPEventReceiverBase
    Microsoft.SharePoint.SPItemEventReceiver
    Microsoft.SharePoint.SPListEventReceiver
    Microsoft.SharePoint.SPWebEventReceiver

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public Class SPEventReceiverBase

Dim instance As SPEventReceiverBase
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPEventReceiverBase

Remarks

The SPEventReceiverBase class is not 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.

Examples

The following code example shows how to register a custom event receiver that traps Web site deletion.

Dim webSite As SPWeb = New SPSite("http://localhost").OpenWeb()
Dim newReceiver As SPEventReceiverDefinition = webSite.EventReceivers.Add()
newReceiver.Class = "Receiver.Class1"
newReceiver.Assembly = "Receiver, Version=1.0.0.0, 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=1.0.0.0, Culture=neutral, PublicKeyToken =10b23036c9b36d6d";
newReceiver.SequenceNumber = 3000;
newReceiver.Type = SPEventReceiverType.SiteDeleting;
newReceiver.Update();
oWebsite.Dispose();

Note

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 Best Practices: Using Disposable Windows SharePoint Services 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

Reference

SPEventReceiverBase Members

Microsoft.SharePoint Namespace