A Simple Event handler
Creating a simple Event handler – inheriting SPEventReceivers such as SPItemEventReceiver, SPListEventReceiver
Feature File
<?xml
version="1.0"
encoding="utf-8"?>
<Feature
Scope="Web"
Title="Simple Event Handler Registration"
Id="69322A1C-0618-43eb-813B-82F02CBA9634"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest
Location="Elements.xml"/>
</ElementManifests>
</Feature>
-------------------
Elements File
<?xml
version="1.0"
encoding="utf-8"?>
<Elements
xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers
ListTemplateId="104">
<Receiver>
<Name>MyEventHandlers</Name>
<Type>ItemDeleting</Type>
<SequenceNumber>10000</SequenceNumber>
<Assembly>SDKSPEvents, Version=1.0.0.0, Culture=neutral, PublicKeyToken=89d0c098ec698224</Assembly>
<Class>SDKSPEvents.SimpleEventHandler</Class>
<Data></Data>
<Filter></Filter>
</Receiver>
</Receivers>
</Elements>
-----------
Now the class file implementing the SPItemEventReceiver for item level event handling. All the levels have their respective EventReceiver (ex. SPListEventReceiver)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace SDKSPEvents
{
public
class
SimpleEventHandler : SPItemEventReceiver
{
public
override
void ItemDeleting(SPItemEventProperties properties)
{
//base.ItemDeleting(properties);
properties.Cancel = true;
properties.ErrorMessage = "Deleting not Permitted";
}
}
public
class
sim : SPListEventReceiver
{
public
override
void FieldDeleting(SPListEventProperties properties)
{
properties.Cancel = true;
properties.ErrorMessage = "Deleting not Permitted";
}
}
}
................HaPpY CoDinG
Partha (Aurum)
No comments:
Post a Comment