How to count the number of alerts using latest release of CSOM


Krishna KV
Team Leader, Aspire Systems
Published On :   02 Mar 2017
Visit Count
Today :  2    Total :   1838
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial


In this article we can have a look into the code snippet to get the count of alerts with the latest version of CSOM that was released during Jan 2017. More information on this release can be found here.

Steps

1. Create a new Console application project

2. Add Microsoft.sharepointonline.csom package using nuget package manager.

clip_image002

 public static SecureString PasswordToSecure(string password)
 {
 	if (string.IsNullOrWhiteSpace(password))
 		return null;
 	else
 	{
 		SecureString secureString = new SecureString();
 		foreach (char c in password.ToCharArray())
 			secureString.AppendChar(c);
 		return secureString;
 	}
 }
 
 static void Main(string[] args)
 {
 	using (var clientContext = new ClientContext("https://domain.sharepoint.com/sites/dev"))
 	{
 		var password = PasswordToSecure("xxxx");
 		clientContext.Credentials = new SharePointOnlineCredentials("xxx@xxx.onmicrosoft.com",password );
 		var currentUser = clientContext.Web.CurrentUser;
 
 		var alerts = currentUser.Alerts;
 
 		clientContext.Load(alerts);
 		clientContext.ExecuteQuery();
 		Console.WriteLine("Total number alerts : " + alerts.Count);
 		Console.ReadLine();
 
 	}
 }
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Forms App