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.
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();
}
}
Leave a comment