0

Using CSOM, I am able to retrieve the collection of alerts for a SharePoint Online site and disable each alert using the following code:

context.Load(context.Web.Alerts,
        collection => collection.Include(
            alert => alert.ID,
            alert => alert.Status
        )
);
context.ExecuteQueryWithRetry();

foreach (SP.Alert alert in context.Web.Alerts) {
    if (alert.Status == AlertStatus.On) {
        context.Load(alert);
        alert.Status = AlertStatus.Off;
        alert.UpdateAlert();
    }
}
context.ExecuteQueryWithRetry();

This doesn't work for SharePoint 2013 though. I get the error: "Field or property 'Alerts' does not exist".

Can this be done with CSOM?

0

SharePoint 2013 On-Premise CSOM Web object didn't support Alerts property.

Please use SharePoint Server Object Model below instead:

            using (SPSite site=new SPSite("http://sp/sites/MyDev"))
            {
                SPWeb web = site.OpenWeb();
                SPAlertCollection alerts = web.Alerts;
                foreach (SPAlert alert in alerts)
                {
                    alert.Status = SPAlertStatus.Off;
                    alert.Update();
                    web.Update();
                }
            }

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.