How to disable SharePoint 2013 alerts using CSOM

g h 716 Reputation points
2021-01-18T06:12:25.1+00:00

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

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

Can this be done with SharePoint 2013 Server CSOM?

57447-csom.png

Microsoft 365 and Office SharePoint Server Development
0 comments No comments
{count} votes

Accepted answer
  1. ZhengyuGuo 10,586 Reputation points Moderator
    2021-01-19T02:05:29.71+00:00

    Hi @g h ,

    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();  
                    }  
                }  
    

    Thanks
    Best Regards


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.