2

I need to make changes to a lot of files in a document library. A lot of users have e-mail alerts enabled on this folder. How can I temporarily disable alerts being sent for this document library?

I've found an option for the web application in Central Administration. But this is for the entire web application, and I don't know if this removes the existing alerts, or simply deactivates them: Central Administration->Web application management->general settings

How can I disable alerts being sent for a document library?

Thank you for reading.

1
  • 1
    Apparently I can't comment, but it's important to note that the solution above does not store the current status of alerts for later. What if a few alerts were already turned off? This solution will turn them back on again which could be undesired behavior.
    – MatsonPP
    Commented May 30, 2014 at 10:36

1 Answer 1

4

Make a console application with the following code to Disable/Enable alerts on a SharePoint 2010/2007 list/Library.

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

namespace EnableDisableAlertsInList
{
    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.)'http://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();
        }
    }
}
}

Source

Hope the above code helps you :)

4
  • Can you tell me how i can make the console application? Is there no out of the box way in SharePoint 2010 to disable the alerts?
    – TempaC
    Commented Oct 28, 2013 at 15:23
  • 1
    To create console application, kindly follow as mentioned in the below URL msdn.microsoft.com/en-us/library/ms438026.ASPX Commented Oct 28, 2013 at 15:51
  • Would it be possible to compile the above code in Eclipse? What code language is this? Also, the code seems to deal with lists only. Are lists and libraries queried the same in SharePoint?
    – TempaC
    Commented Oct 29, 2013 at 8:21
  • 2
    @TempaC, the above code is C# code, AFAIK c# code cannot be used in Eclipse. Lists and libraries are queried in the same way :) Commented Oct 29, 2013 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.