Wss3sdk: how to create an event handler feature

Source: Internet
Author: User

This example shows how to add a simple event processor to prevent deleting list items from a list. This task includes two steps:

    • Create event processing in Visual StudioProgram
    • Add event handlers to WSS as feature
Create an event handler in vistual Studio
  1. In Visual Studio, clickFile->New->ProjectTo create a new project
  2. In the Create Project dialog box, select the project typeVisual C #, Template SelectionClass Library, Enter in the Name boxDeletingeventhandlerAnd then click OK.

  3. In solution manager, selectDeletingeventhandler, InProjectClick Add reference in the menu.

  4. In the Add reference dialog box, selectMicrosoft. SharePoint(Located in. NetLabel) and click OK.
  5. InCodeIn the editor, referenceMicrosoft. SharePointThe namespace is as follows: UsingMicrosoft. SharePoint;
  6. Change the class nameDeletingactionAnd make it inherit fromSpitemeventreceiverClass: Public ClassDeletingaction: spitemeventreceiver
  7. Use the following code to override the itemdeleting method of the class.

    Public   Override   Void Itemdeleting (spitemeventproperties properties)
    {
    Properties. Cancel =   True ;
    Properties. errormessage =   " Deleting items from "   + Properties. relativeweburl +   " Is not supported. " ;
    }
  8. In solution manager, right-clickDeletingeventhandlerNode, PointAttribute.

  9. In the Properties dialog box, clickSignatureLabel, selectSign this component, ClickSelect a strongly-named key fileAnd then click<New...>.

  10. In the create strong naming key dialog box, enterDeletingeventhandler. SNKAs the key file name, you can also specify a password for the key and click OK.

  11. Use the shortcut key Ctrl + Shift + B to compile the project.

  12. In the Visual Studio project folder, find\ Deletingeventhandler \ bin \ debugFolder, drag and drop the deletingeventhandler. dll fileLocal_drive: \ windows \ assemblyTo perform global DLL deployment.

Add event processors as feature
  1. InLocal_drive:/Program files/common files/Microsoft shared/Web Server Extensions/12/template/FeaturesCreate a folder namedDeletingeventhandler.

  2. Create a new feature. xml file in the folder to identify the feature. The content is as follows. The featuer scope is the website. < Feature Scope = "Web"
    Title = "Deleting event handler"
    ID = "Guid"
    Xmlns = "Http://schemas.microsoft.com/sharepoint" >
    < Elementmanifests >
    < Elementmanifest Location = "Elements. xml" />
    </ Elementmanifests >
    </ Feature >

     

  3. Replace the guid placeholder in the previous step. You can generate a new guid through guidgen.exe. The command line tool is located inLocal_drive: \ Program Files \ Microsoft Visual Studio 8.

  4. Create an element file elements. xml file in the deletingeventhandler folder to identify the components, classes, and methods of the event handler. In this example, the event handler is applied to the list of all notifications on the website. < Elements Xmlns = "Http://schemas.microsoft.com/sharepoint" >
    < Receivers Listtemplateid = "104" >
    < Cycler >
    < 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 >
    </ Cycler >
    </ Receivers >
    </ Elements >

     

  5. You can use the following method to obtain the Public Key token of the component. FindLocal_drive: \ Windows \ assemblyDeletingeventhandler. dll file, right-click the file, and clickAttributeIn the Properties dialog boxAverageLabel, select and copy the token.

  6. In the command line, enter the following command to install and activate feature, and then restart IIS (Microsoft Internet Information Services) for the change to take effect.

    Stsadm - O installfeature - filename deletingeventhandler \ feature. XML

    stsadm - O activatefeature - filename deletingeventhandler \ feature. XML - URL http: // server / site / subsite

    iisreset

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.