SharePoint event receivers help developers automate processes when specific actions occur within the SharePoint environment. These receivers act as listeners that trigger custom code when events happen, such as when items are added to lists, documents are uploaded, or workflows are initiated. Event receivers can be implemented in various on-premises versions of SharePoint.
The functionality of event receivers extends beyond simple notifications. They can perform complex actions like creating unique IDs, establishing folder structures automatically, sending email notifications, or validating data.
SharePoint Developers typically create these receivers using Visual Studio and can deploy them through SharePoint solutions or PowerShell scripts, depending on the specific requirements and SharePoint environment.
What is a SharePoint Event Receiver?
A SharePoint Event Receiver is a component that handles specific actions within SharePoint sites, lists, and libraries. Event Receivers respond to user activities like adding, updating, or deleting items in SharePoint.
Event Receivers come in two main types:
- Synchronous Event Receivers (Before Events) – These run before an action completes, allowing you to check conditions or cancel operations. For example, checking if a user has proper permissions before they delete a list item.
- Asynchronous Event Receivers (After Events) – These run after an action finishes, perfect for notifications or follow-up tasks. For instance, sending an email to a manager when someone uploads a document.
SharePoint offers several base classes for creating Event Receivers:
| Base Class | Purpose |
|---|---|
| SPItemEventReceiver | For list item events |
| SPListEventReceiver | For list-level events |
| SPEmailEventReceiver | For email-related events |
| SPWebEventReceiver | For web site events |
| SPWorkflowEventReceiver | For workflow events |
Common uses for Event Receivers include:
- Sending notifications when files are uploaded
- Creating approval workflows
- Validating data before saving
- Logging changes to SharePoint content
Event receivers work across all on-premises versions of SharePoint. In newer SharePoint solutions, Remote Event Receivers (RERs) allow event handling through external web services.
Event Receiver Example in SharePoint
SharePoint event receivers help automate processes when specific actions occur in SharePoint. This example shows how to create an event receiver that generates a unique project ID and automatically builds folder structures.
Prerequisites
Before creating the event receiver, you need:
- A Project Master List – to store project information
- A Deliverable Library – where folders will be created automatically
Create the Event Receiver in SharePoint using Visual Studio
Follow the steps below to create an event receiver in SharePoint using Visual Studio.
- Open Visual Studio -> Go to Solution Explorer -> Create a New Item -> Choose Event Receiver -> Click on the Add button

- The next page will appear, allowing you to choose Event Receiver Settings. Here, you can select List Item Events and a custom list in the event source. Next, you can select the An item was added event, as per the screenshot below.

- Next, you can follow the code below to use in your Visual Studio snippet to achieve your goal.
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
namespace SharePoint_Webparts.Create_Folder
{
/// <summary>
/// List Item Events
/// </summary>
public class Create_Folder : SPItemEventReceiver
{
/// <summary>
/// An item was added.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
string Siteurl = properties.ListItem.Web.Url;
using (SPSite site = new SPSite(Siteurl))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPListItem currentItem = properties.ListItem;
currentItem["Project_ID"] = "KM-ID00" + Convert.ToInt32(properties.ListItem["ID"]).ToString();
currentItem.Update();
SPList spl = web.Lists["Deliverable Library"];
var FolderAdded = spl.Items.Add("", SPFileSystemObjectType.Folder, "KM-ID00" + Convert.ToInt32(properties.ListItem["ID"]).ToString());
FolderAdded.Update();
string[] namesArray = new string[] { "Analysis", "Design", "Development", "Testing", "Deployment" };
foreach (string name in namesArray)
{
SPListItem SubFolder = spl.AddItem(FolderAdded.Folder.ServerRelativeUrl, SPFileSystemObjectType.Folder, name);
SubFolder.Update();
}
web.AllowUnsafeUpdates = false;
}
}
}
}
}- In Element.xml, you need to modify the Receivers List URL instead of the List template ID. You have to update your list URL here.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListUrl="/sites/KMIntranet/Lists/Project%20Master">
<Receiver>
<Name>Create_FolderItemAdded</Name>
<Type>ItemAdded</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePoint_Webparts.Create_Folder.Create_Folder</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>
</Elements>- Once your code is ready, right-click on the Solution Explorer and deploy the solution.
- Next, go back to your list and add an item to see what happens. Here, Project_ID will be generated automatically after you save your data. Please look at the screenshot below, which shows the Project_ID column.

- At the same time, if you open your SharePoint document library, a folder with the same name is created.

- If you open the folder, the folder structure is created automatically here. Please look at the screenshot.

Check out Display Modal Pop-ups in SharePoint
BeforeProperties and AfterProperties in Event Receivers in SharePoint
Event receivers in SharePoint help developers control what happens when items change. Two important properties – BeforeProperties and AfterProperties – let you access the original and changed values of list items or documents. Understanding how these properties work is essential for creating effective event receivers.
How BeforeProperties and AfterProperties Work in SharePoint Lists
When working with SharePoint lists, these properties behave in specific ways depending on the event:
| Event | BeforeProperties | AfterProperties | properties.ListItem |
|---|---|---|---|
| ItemAdding | Not available | Contains new values | Null |
| ItemAdded | Not available | Contains new values | Contains new values |
| ItemUpdating | Not available | Contains changed values | Contains original values |
| ItemUpdated | Not available | Contains changed values | Contains changed values |
| ItemDeleting | Not available | Not available | Contains original values |
| ItemDeleted | Not available | Not available | Null |
For SharePoint lists, the BeforeProperties collection doesn’t provide reliable data. Instead, when handling update events, you should use properties.ListItem to access original values during the ItemUpdating event.
For example, if you need to compare the original value with a new one in a list item update, you would use:
// For list items during ItemUpdating
string oldValue = properties.ListItem["FieldName"].ToString();
string newValue = properties.AfterProperties["FieldName"].ToString();This approach is necessary because BeforeProperties doesn’t contain reliable data for list items.
How BeforeProperties and AfterProperties Work in SharePoint Document Libraries
Document libraries handle these properties differently:
| Event | BeforeProperties | AfterProperties | properties.ListItem |
|---|---|---|---|
| ItemAdding | Not available | Not available | Null |
| ItemAdded | Not available | Not available | Contains new values |
| ItemUpdating | Contains original values | Contains changed values | Contains original values |
| ItemUpdated | Contains original values | Contains changed values | Contains changed values |
| ItemDeleting | Not available | Not available | Contains original values |
| ItemDeleted | Not available | Not available | Null |
For document libraries, both BeforeProperties and AfterProperties are available and reliable during update events. This makes it easier to compare previous and current values.
When working with document libraries, you can compare values this way:
// For document libraries during ItemUpdating or ItemUpdated
if (properties.BeforeProperties["FieldName"] != properties.AfterProperties["FieldName"])
{
// Take action based on the change
}You can use these properties to:
- Prevent users from changing specific fields
- Log changes to important documents
- Trigger workflows based on specific field changes
- Validate changes before they’re saved
If you want to compare a column value from the old value with the updated value, then you can write like below:
public override void ItemUpdating(SPItemEventProperties properties)
{
if (properties.BeforeProperties[“column”] != properties.AfterProperties[“column”])
{
properties.Cancel = true;
properties.ErrorMessage = “This column cannot be changed”;
}
}In this tutorial, I have explained how to work with event receivers in SharePoint using Visual Studio.
You may also like the following tutorials:
- JavaScript Client Object Model (JSOM) in SharePoint
- SharePoint .NET Client Object Model Examples
- SharePoint JSLink Examples
- SPServices in SharePoint

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (12 times). I have also worked in companies like HP, TCS, KPIT, etc.