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 :)