Elczar Adame's Shared Points on SharePoint


SharePoint 2010 has synchronous and asynchronous events that could programmatically be overridden. We can build custom event receivers that execute actions before (synchronous) or after (asynchronous) events on SharePoint site.

A SharePoint event handler may be a list, list item, list email, list workflow, or web event. This piece will show us how to add an event to the updating of list items.

1. We will start by creating a custom list in our SharePoint site.

1

2. Next, we will open our Microsoft Visual Studio 2010 and create a project using SharePoint 2010 Event Receiver template.

2

Let us make sure that the Visual Web Developer components are installed. Else, we will be prompted by the error below:

3

3. Along the process of project creation, we will choose the Deploy as a farm solution option as the trust/security level of the solution we are creating.

4

4. For our purpose, we will be choosing the List Item Events as the event receiver type and An item is being updated as the event to be handled.

5

5. Let us open our event receiver class and write the lines below. Note that the <SharePoint List Name> is the name of the list we have created in the first step.

public override void ItemUpdating(SPItemEventProperties
properties)
{
     if (properties.List.Title == "<SharePoint List Name>")
     {
          properties.Cancel = true;
          properties.ErrorMessage = "Update is not allowed in;
this list."
     }
}

6. And finally, let us deploy our solution.

6

Let us take note, that we might encounter this error during the deployment. It is normally caused by a misdefined element in our Elements.xml file.

7

Or we might encounter this error during the deployment if our SharePoint 2010 User Code Host service is not running.

8

7. However, if we have successfully deployed our solution and attempt to update an item in the list that we have created in this walkthrough, we will be prompted by the message below, as we have written in our custom event handler.

9

Thank you very much.

Digg This
Advertisements

Comments on: "SharePoint 2010 Event Receiver" (1)

  1. I’m getting the error you mentioned in step-6. Could you please help how to fix it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

%d bloggers like this: