I am trying to get all user alerts[Under Site setting] for all the sub-sites under site collection using client object model.


If you are using SharePoint Online, you can get user alerts like this:

        string userName = "xxx@xxx.onmicrosoft.com";
        string password = "xx";
        var securePassword = new SecureString();
        foreach (char c in password)
        using (var clientContext = new ClientContext("https://xxx.sharepoint.com/sites/xxx"))
            clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
            Web web = clientContext.Web;

                var siteUsersColl = from user in web.SiteUsers
                                    where user.PrincipalType == Microsoft.SharePoint.Client.Utilities.PrincipalType.User
                                    select user;
                var usersResult = clientContext.LoadQuery(siteUsersColl);

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

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

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

                    count += alerts.Count;

The alerts object is available for SharePoint Online from Jan. 2017:

New SharePoint CSOM version released for SharePoint Online – January 2017

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.