2

I want to use microsoft.Sharepoint.client.dll and microsoft.Sharepoint.client.runtime.dll to retrieve the list of user alerts.

Can any one please let me know how to retrieve the user alerts from sharepoint site.

1

Try the below code:

//load all users in the site collection
var siteUsersColl = from user in oWeb.SiteUsers
                where user.PrincipalType == Microsoft.SharePoint.Client.Utilities.PrincipalType.User
                select user;
var usersResult = context.LoadQuery(siteUsersColl);
context.ExecuteQuery();

int count = 0;
foreach (var user in siteUsersColl)
{
    //ensure that user is present
    var curruser = oWeb.EnsureUser(user.LoginName);

    //load the users alerts, available after jan 2017 CSOM update in SPO, not sure about OnPrem
    var alerts = user.Alerts;
    context.Load(alerts);
    context.ExecuteQuery();

    foreach (Alert alert in alerts)
    {
        //get the alert
        var type = alert.Title;
    }

    count += alerts.Count;
}

Reference - CSOM January 2017 update

3
  • Thanks a lot, I succeeded 50 % how bout retrieving the list name as it is giving property not initialized exception. if i access like alert.List.Title – Suresh Bolineni Apr 3 '17 at 11:17
  • Try it as below: ` foreach (Alert alert in alerts) { //get the alert var type = alert.Title; context.Load(alert.List,a => a.Title); context.ExecuteQuery(); var listTitle = alert.List.Title; }` you need to load the list object and then execute the query – Gautam Sheth Apr 3 '17 at 11:23
  • i tired with this but giving null reference exception.. :( – Suresh Bolineni Apr 3 '17 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.