How to Attach Event Receivers to a Web in SharePoint Office 365 Programmatically using CSOM C#

Sathish Nadarajan
SharePoint MVP
Published On :   24 Jan 2017
Visit Count
Today :  3    Total :   2109
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

Sharegate: Kick-Ass Tool
Think Your SharePoint & Office 365 Are Secure ? Find Out Now!

In this article, we will be seeing how to add the Event Receiver to a Web in SharePoint Office 365 Programmatically using CSOM C#

 namespace Console.Office365
     using Microsoft.SharePoint.Client;
     using Microsoft.SharePoint.Client.Taxonomy;
     using Newtonsoft.Json.Linq;
     using System;
     using System.Collections.Generic;
     using System.IO;
     using System.Linq;
     using System.Threading.Tasks;
     class Program
         static void Main(string[] args)
         public static void AttachEventReceivers()
             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
             string siteUrl = "https://*********";
             string userName = "Sathish@*****";
             string password = "*********";
             using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
                 Web web = ctx.Web;
                 #region Attach Document List Created Event Receiver
                 var receiver = new EventReceiverDefinitionCreationInformation();
                 receiver.EventType = EventReceiverType.ListAdded;
                 receiver.ReceiverUrl = new Uri("https://<<>>").AbsoluteUri;
                 receiver.ReceiverName = "<<Receiver Name>>";
                 receiver.Synchronization = EventReceiverSynchronization.Asynchronous;

Happy Coding,

Sathish Nadarajan.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.

Protect Your SharePoint