Todd Baginski's Blog - A SharePoint, Mobile, Office365, PowerApps and Azure Blog

How To Create Office 365 SharePoint Alerts With The Client Side Object Model (CSOM)

31 January 2017

Comments:

Off
 January 31, 2017
 Off
OSU vs BG 2016

This week Microsoft released some new updates for the Office 365 Client Side Object Model (CSOM).  These updates include the ability to work with SharePoint alerts!  You can read more about it here.

I created a console application to demonstrate how to create and read alerts. You can get the full source code in GitHub here.

February 24, 2017 Update:  The February 2017 CSOM release (version 16.1.6216.1200) fixed the issue with the EventType and Filter properties.  The code has been updated in the GitHub repository accordingly.

Currently, there is a bug in the CSOM that affects creating the alerts. The sample console application I created works around the bug. Thanks Vesa Juvonen for verifying the bug and showing me the workaround! See the comments in the code that describe the bug and how to work around it.

// These two properties currently have no impact on alert creation.
// This is a known bug. If you set these properties and do not use the property bag
// you will receive an Object reference not set to an instance of an object exception.
// myNewAlert.EventType = AlertEventType.All;
// myNewAlert.Filter = "0";

// Currently, you need to use the property bag entries below to create the alert.
Dictionary<string, string> properties = new Dictionary<string, string>()
{
{ "eventtypeindex", "0" },
//Change Type:
// 0 = All Changes
// 1 = New items added
// 2 = New items are added
// 3 = Existing items are modified
{ "FilterIndex", "0" }
//Send Me and alert when:
// 0 = Anything Changes
// 1 = Someone else changes a document
// 2 = Someone else changes a document created by me
// 3 = Someone else changes a document modified by me
};

Here’s what it looks like in action.

O365 CSOM Alerts

Comments are closed.