Elczar Adame's Shared Points on SharePoint

Posts tagged ‘Activate Features Error’

SharePoint 2010 Event Receiver

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.


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


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


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. 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. 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
     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.


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.


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


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.


Thank you very much.

Digg This

Tag Cloud