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

Krishna KV
 
Team Leader, Aspire Systems
March 2, 2017
 
Rate this article
 
Views
3503

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();
 
 	}
 }

Author Info

Krishna KV
 
Team Leader, Aspire Systems
 
Rate this article
 
Krishna K.V has been working in IT Industry for over 7+ years. He holds a Master Degree in Information Technology. He is more interested to learn and share new technologies, ...read more
 

Leave a comment