This example simply shows how to handle delete item event of list in share point.
Create the event handler in visual studio
{
properties.Cancel = true;
properties.ErrorMessage = "You can not delete item from " +
properties.RelativeWebUrl;
}
6. In Solution Explorer, right-click the DeletingEventHandlernode, and then click
Properties.
7. In the Properties dialog box, click the Signing tab, selectSign the asembly, select
Choose a strong name key file, and then click.
8. In the Create Strong Name Key dialog box, typeDeletingEventHandler.snk in the
Key file name box, optionally specify a password for the key, and then click OK.
9. Build the project.
10. Find the
drag the DeletingEventHandler.dll file to
DLL in the global assembly cache.
To Add Event handler as a windows share point services feature
Reference - http://msdn.microsoft.com/
Create the event handler in visual studio
- Create a new project in Visual Studio by clicking File, pointing to New, and then clicking Project.
- In the New Project dialog box, select Visual C# in theProject types box, select Class Library in theTemplates box, type DeletingEventHandler in theName box, and then click OK.
- In Solution Explorer, select DeletingEventHandler, and click Add Reference on the Project menu.
- In the Add Reference dialog box, selectMicrosoft.SharePoint on the .NET tab and then clickOK.
- Add the following code within the class to override theItemDeleting method.
{
properties.Cancel = true;
properties.ErrorMessage = "You can not delete item from " +
properties.RelativeWebUrl;
}
6. In Solution Explorer, right-click the DeletingEventHandlernode, and then click
Properties.
7. In the Properties dialog box, click the Signing tab, selectSign the asembly, select
Choose a strong name key file, and then click
8. In the Create Strong Name Key dialog box, typeDeletingEventHandler.snk in the
Key file name box, optionally specify a password for the key, and then click OK.
9. Build the project.
10. Find the
\DeletingEventHandler\bin\Debug
folder in the Visual Studio Projects folder, anddrag the DeletingEventHandler.dll file to
Local_Drive:\WINDOWS\assembly
to place theDLL in the global assembly cache.
To Add Event handler as a windows share point services feature
- Create a folder in Local_Drive
:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES
calledDeletingEventHandler. - Create a Feature.xml file in this folder like the following that identifies the Feature and its element manifest file and sets the Feature scope to Web site.
XmlGUID"> xmlns="http://schemas.microsoft.com/sharepoint/"> - To replace the GUID placeholder in the previous Idattribute, generate a GUID by running guidgen.exe located in Local_Drive
:\Program Files\Microsoft Visual Studio 8
. - Create an Elements.xml file in the DeletingEventHandler folder that identifies the assembly, class, and method to implement as the event handler. This example applies the event handler to all announcements lists of a site, as specified by the ListTemplateId attribute. For the IDs of other default Windows SharePoint Services list template types, see the Type attribute description of theListTemplate element.
Xml<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Receivers ListTemplateId="104"> <Receiver> <Name>DeletingEventHandlerName> <Type>ItemDeletingType> <SequenceNumber>10000SequenceNumber> <Assembly>DeletingEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a26b5449ac4a4cf3Assembly> <Class>DeletingEventHandler.DeletingActionClass> <Data>Data> <Filter>Filter> Receiver> Receivers> Elements>
- To get the Public Key Token of the assembly, in Windows Explorer find the DeletingEventHandler.dll file in theLocal_Drive
:\WINDOWS\assembly
, right-click the file, clickProperties, and on the General tab of the Propertiesdialog box, select and copy the token. - At a command prompt, navigate to
\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
on the local drive, and type each of the following commands to install the Feature in the deployment, activate the Feature on a specified subsite, and reset Microsoft Internet Information Services (IIS) so that the changes take effect:
stsadm -o installfeature -filename DeletingEventHandler\Feature.xml stsadm -o activatefeature -filename DeletingEventHandler\Feature.xml -url http://Server/Site/Subsite iisreset
- Try to delete an item in an announcements list on the specified Web site to see the effects of the event handler Feature
Reference - http://msdn.microsoft.com/
No comments:
Post a Comment