1)Create Class Library project using visual studio
2)Add reference-->browse
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI
select Microsoft.sharepoint.dll
3)Add namespace
using Microsoft.SharePoint;
4)Inherit SPItemEventReceiver class like below
public class EventReceiversForDemolistinCMS:SPItemEventReceiver
{
}
5)Override Method properties as per our requirement.
public class EventReceiversForDemolistinCMS:SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
}
public override void ItemAdded(SPItemEventProperties properties)
{
}
public override void ItemUpdating(SPItemEventProperties properties)
{
}
public override void ItemUpdated(SPItemEventProperties properties)
{
}
public override void ItemDeleting(SPItemEventProperties properties)
{
}
public override void ItemDeleted(SPItemEventProperties properties)
{
}
}
6)Here i am taking simple example.I want to raise event for an item when item is added in the list.For that i will override Itemadded event as live below.
public class EventReceiversForDemolistinCMS:SPItemEventReceiver
{
public override void ItemAdding(SPItemEventProperties properties)
{
string strtemp = properties.AfterProperties["Status"].ToString();
if (strtemp != "Completed")
{
properties.ErrorMessage = "Status should be completed";
properties.Cancel = true;
}
}
}
In the above above code getting the value of Status column field while adding item to the list.
properties.AfterProperties["Status"].ToString(); //IT will get Status filed value after ading value in the column.
In the Condition it is checking Status value ,If status value is equal to Completed it will add item to the list,If status couln is not equal to Completed it will raise an error.
7)Add Strong name to the project
right click on project-->properties-->signinig-->
select sign in assembly-->click on dropdown-->New ->any name-->un select protect my key with password-->say ok
8)Build the applciation
9)Find the dll by opening contaiing folder-->bin/debug path
10)Place in GAC
Adding eventreceviers as a feature
Showing posts with label Event Receivers. Show all posts
Showing posts with label Event Receivers. Show all posts
Monday, July 19, 2010
Introduction
What are Event Receivers?
SharePoint 2007 Event Receivers are a type of feature which listens for certain events on a site, list or list item. Event Receivers are the MOSS version of document event handlers (also known as Event Sink) in SharePoint V2 technologies (WSS and SPS). Previously the document event handlers were only available for document libaries. Event receivers are now available for any type of list.
What can they be used for?
SharePoint 2007 Event Receivers add behaviours to lists or list items. They are commonly used to perform data validation (beyond SharePoint standard capabilities), to ensure data integrity or to perform a business process.
Definition
Event Receivers have before and after events.
The events relating to a site are:
Before
SiteDeleting
WebDeleting
WebMoving
After
SiteDeleted
WebDeleted
WebMoved
A class needs to inherit from SPWebEventReceiver. The behaviour is defined by overriding a method for one of the above before or after events. You can access properties that relates to the event that the feature is listening using SPWebEventProperties.
The events relating to a list are:
Before
FieldAdding
FieldUpdating
FieldDeleting
After
FieldAdded
FieldUpdated
FieldDeleted
A class needs to inherit from SPListEventReceiver. You define the behaviour by overriding a method for one of the above before or after events. You can access the event properties using the parameter SPListEventProperties.
The events releating to list items are:
Before
ItemAdding
ItemUpdating
ItemDeleting
After
ItemAdded
ItemUpdated
ItemDeleted
ItemAttachmentAdded
ItemAttachmentDeleted
ItemCheckedIn
ItemCheckedOut
ItemFileConverted
ItemFileMoved
ItemUncheckedOut
A class needs to inherit from SPItemEventReceiver. You then override a method for one of the above before or after events. The event properties can be accessed by the local parameter SPItemEventProperties. One of these is the list item. For example:
public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem currentListItem = properties.ListItem;
// other implementation here .....
}
Other important information of the properties object is the AfterProperties and BeforeProperties. AfterProperties provide access to the modified properties. BeforeProperties provide access to the column data before it was changed. This enables you to perform changed based validation.
SharePoint 2007 Event Receivers are a type of feature which listens for certain events on a site, list or list item. Event Receivers are the MOSS version of document event handlers (also known as Event Sink) in SharePoint V2 technologies (WSS and SPS). Previously the document event handlers were only available for document libaries. Event receivers are now available for any type of list.
What can they be used for?
SharePoint 2007 Event Receivers add behaviours to lists or list items. They are commonly used to perform data validation (beyond SharePoint standard capabilities), to ensure data integrity or to perform a business process.
Definition
Event Receivers have before and after events.
The events relating to a site are:
Before
SiteDeleting
WebDeleting
WebMoving
After
SiteDeleted
WebDeleted
WebMoved
A class needs to inherit from SPWebEventReceiver. The behaviour is defined by overriding a method for one of the above before or after events. You can access properties that relates to the event that the feature is listening using SPWebEventProperties.
The events relating to a list are:
Before
FieldAdding
FieldUpdating
FieldDeleting
After
FieldAdded
FieldUpdated
FieldDeleted
A class needs to inherit from SPListEventReceiver. You define the behaviour by overriding a method for one of the above before or after events. You can access the event properties using the parameter SPListEventProperties.
The events releating to list items are:
Before
ItemAdding
ItemUpdating
ItemDeleting
After
ItemAdded
ItemUpdated
ItemDeleted
ItemAttachmentAdded
ItemAttachmentDeleted
ItemCheckedIn
ItemCheckedOut
ItemFileConverted
ItemFileMoved
ItemUncheckedOut
A class needs to inherit from SPItemEventReceiver. You then override a method for one of the above before or after events. The event properties can be accessed by the local parameter SPItemEventProperties. One of these is the list item. For example:
public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem currentListItem = properties.ListItem;
// other implementation here .....
}
Other important information of the properties object is the AfterProperties and BeforeProperties. AfterProperties provide access to the modified properties. BeforeProperties provide access to the column data before it was changed. This enables you to perform changed based validation.
Subscribe to:
Posts (Atom)
Content Editor Webpart not showing up in SharePoint Online ------------------------------------------------------------------------------...
-
Ribbon missing in Share point online Pages to add custom web part : --------------------------------------------------------------------...
-
Content Editor Webpart not showing up in SharePoint Online ------------------------------------------------------------------------------...
-
Sharepoint Online Management Shell ------------------------------------------------------------------------------------------------------...