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?

1 Answer 1

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();
                }
            }
1
  • Seems the same question has been answered here: stackoverflow.com/questions/64807932/…, If it helps to resolve the question, I suggest you could also accept as answer to close this question. Thanks :-)
    – Jerry
    Nov 18, 2020 at 8:44

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.