Disable Alerts from a SharePoint List or Library

The end-user came up with a requirement: Disable alerts from a particular SharePoint list, where 100’s of people subscribed already.

Its apparent that we can disable alerts for web application either from Central Administration or executing the stsadm:
stsadm -o setproperty -url https://server_name -pn alerts-enabled -pv false

But here the requirement is to disable alert for a particular library ONLY for some time, and enable it back once the user done with his editing.

I remember SPAlert class has a Status property. why don’t to try setting it OFF? Sounds good! Lets jump to coding, make a console application and give it to the SharePoint Administrator to disable alerts on a SharePoint 2010/2007 list.

Disable alerts for SharePoint list Programmatically:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;

namespace TurnAlertsOnOff
{
    class Program
    {
        static void Main(string[] args)
        {
            string site;
            string web;
            string list;
            string option;
            SPSite tmpSite=null;

            try
            {
                //Get the site collection , Sub-site, Lists
                if (args.Length != 3)
                {
                    //Site collection
                    Console.WriteLine("Enter the Site collection URL (E.g.)'https://intranet.company.com' : \n ----------------------------------- \n");
                    site = Console.ReadLine();

                    //Sub-Site
                    Console.WriteLine("\n Enter the Sub-Site URL (E.g.) '/Sales/us' (  '/' for root web): \n -------------------------------------- ");
                    web = Console.ReadLine();

                    //List
                    Console.WriteLine("\n Enter the List Name(Title): (E.g) 'Announcements' : \n -------------------------------------- ");
                    list = Console.ReadLine();

                    //Option ON or OFF
                    Console.WriteLine("\n Enter the Option ON or OFF: \n ----------------------------------- \n ");
                    option = Console.ReadLine();

                }
                else
                {
                    site = args[0];
                    web = args[1];
                    list = args[2];
                    option = args[3];
                }

                tmpSite = new SPSite(site);
                SPWeb tmpWeb = tmpSite.OpenWeb(web);
                SPList tmpList = tmpWeb.Lists[list];

                long alertCounter = 0;
                foreach (SPAlert tmpAlert in tmpWeb.Alerts)
                {
                    option = option.ToUpper();

                    if (option == "ON") //Turn it ON
                    {
                        if ((tmpAlert.List.Title == tmpList.Title) & (tmpAlert.Status == SPAlertStatus.Off))
                        {
                            tmpAlert.Status = SPAlertStatus.On;
                            Console.WriteLine("Turning ON Alert: {0} in List: {1}", tmpAlert.Title, tmpList.Title);
                            tmpAlert.Update();
                            alertCounter++;
                        }
                    }
                    else if (option == "OFF") //Turn it ON
                    {
                        if ((tmpAlert.List.Title == tmpList.Title) & (tmpAlert.Status == SPAlertStatus.On))
                        {
                            tmpAlert.Status = SPAlertStatus.Off;
                            Console.WriteLine("Turning OFF Alert: {0} in List :{1}", tmpAlert.Title, tmpList.Title);
                            tmpAlert.Update();
                            alertCounter++;
                        }

                    }
                }

                //Just to pause
                Console.WriteLine("Done, Processed {0} Alerts! Press a key to Exit.", alertCounter);
                Console.ReadLine();

            }

            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                System.Diagnostics.EventLog.WriteEntry("Disable/Enable Alerts", ex.Message);
                Console.ReadLine();
            }

            finally
            {
                //Dispose of the Root Site Object
                tmpSite.Dispose();
            }
        }
    }
}

Compile and execute the code from server will temporarily remove alert from SharePoint list. You can disable alerts in SharePoint list using PowerShell as well. Refer my old posts: Create – Edit – Find – Delete SharePoint Alerts using PowerShell

Tail: 
You can set the immediate alerts job interval to 1 minute by running:  
stsadm -o setproperty -pn job-immediate-alerts -url https://Intranet.company.com -pv “every 1 minutes”

Related post: Disable alerts in SharePoint using PowerShell

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

8 thoughts on “Disable Alerts from a SharePoint List or Library

  • Where would I apply this? I’m managing a SharePoint 2013 site I inherited. Have a need for a ListCalendar to temporarily disable Alerts during an update process. I’m not a developer, so don’t know a lot of the back end. Thanks in advance.

    Reply
    • You need to create a console application with the above code and run it from your SharePoint server. Or you can use the PowerShell code!

      Reply
  • would this work for SP 2010?

    Reply
  • Niranjan,
    Make sure you are updating the Alert Objects after setting its properties!

    Reply
  • Hi Salaudeen,
    i need to programmatically turn off and on alerts for a list and do batch operation on list data, i followed your blog post and created a alertfunction and implemented like this

    alertfunction(off)
    batchfunction();
    alertfunction(on)

    but still iam getting email alerts,any help will be appreciated

    Reply
    • This code disables ONLY existing alerts in a specific list or library! It doesn’t (of course, can’t!) disable any new alerts you are creating after executing this code on the particular list! You may have to temporarily turn-off alerts on web application level by changing the flag “AlertsEnabled” to “false” as in How to Disable Alerts in SharePoint

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *