SharePoint 2007 开发系列(25) 创建SharePoint Event Handler

Two procedures are involved in this task:

Creating an event handler in MS Visual Studio

Adding the event handler as a feature in WSS V3.0

To create

C# code

public class DeletingAction : SPItemEventReceiver

{

public override void ItemDeleting(SPItemEventProperties properties)

{

properties.Cancel = true;

}

}

To Add

Create a folder in local drive:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES called DeletingEventHandler.

Create Feature.xml and Elements.xml files in this folder.

<Feature Scope="Web"

Title="Deleting Event Handler"

Id="GUID"

xmlns="http://schemas.microsoft.com/sharepoint/">

<ElementManifests>

<ElementManifest Location="Elements.xml"/>

</ElementManifests>

</Feature>

 

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Receivers ListTemplateId="104">

<Receiver>

<Name>DeletingEventHandler</Name>

<Type>ItemDeleting</Type>

<SequenceNumber>10000</SequenceNumber>

<Assembly>DeletingEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a26b5449ac4a4cf3</Assembly>

<Class>DeletingEventHandler.DeletingAction</Class>

<Data></Data>

<Filter></Filter>

</Receiver>

</Receivers>

</Elements>

At a command prompt,

stsadm -o installfeature -filename DeletingEventHandler\Feature.xml

stsadm -o activatefeature -filename DeletingEventHandler\Feature.xml -url http://Server/Site/Subsite

iisreset

http://msdn.microsoft.com/en-us/library/ms453149.aspx

posted @ 2008-12-08 09:50  许晓光  阅读(344)  评论(0编辑  收藏  举报