Wss3sdk How to create an event handler feature

Source: Internet
Author: User
Tags visual studio

This example shows how to add a simple event handler to prevent the deletion of list items from a list. This task consists of two steps:

To create an event handler in Visual Studio

Add an event handler as a feature to WSS

Create an event handler in Vistual Studio

Create a new project by clicking the file-> new-> project in Visual Studio

In the New Project dialog box, select the project type as Visual C #, select the class library for the template, enter Deletingeventhandler in the Name box, and then click OK.

In Solution Manager, select Deletingeventhandler and click Add Reference in the Project menu.

In the Add Reference dialog box, select Microsoft.SharePoint (located in the. NET tab) and click OK.

In the Code Editor, reference the Microsoft.SharePoint namespace as follows:

Using Microsoft.SharePoint;

Change the class name to Deletingaction and make it inherit from the Spitemeventreceiver class, as follows:

public class DeletingAction : SPItemEventReceiver

Use the following code to overwrite 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.";
}

In Solution Manager, right-click the Deletingeventhandler node and point properties.

In the Properties dialog box, click on the Signature tab, select Sign the component, click Select a strong named key file, and then click < New ...

In the Create strong named Key dialog box, enter DELETINGEVENTHANDLER.SNK as the key file name, or you can assign a password to the key and click OK.

Compile the project with the shortcut key ctrl+shift+b.

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.