SharePoint Alerts Report for a List or Library
End-User’s Requirement: I want to see all people who subscribed for my Project site’s “Lessons Learn” List.
Solution: Wrote object model code to retrieve all alerts created on a specific list.
C# Object Model Code to Get All Alerts Created on a SharePoint List or Library & Generate Report:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;
namespace SharePoint.AdminReports
{
class GetAlertsForList
{
static void Main(string[] args)
{
string site;
string web;
string list;
long alertCounter=0;
StreamWriter SW;
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/sites/sales :\n");
site = Console.ReadLine();
//Sub-Site
Console.WriteLine("\nEnter the Sub-Site URL (E.g.) regions/us/ (Press \"Enter\" key for root web): \n");
web = Console.ReadLine();
//List
Console.WriteLine("\nEnter the List/Library Name(Title): (E.g) Announcements: \n");
list = Console.ReadLine();
}
else
{
site = args[0];
web = args[1];
list = args[2];
}
//objects for the CSV file generation
SW = File.AppendText("c:\\AlertsOnList.csv");
//Write the CSV Header
SW.WriteLine("List URL \t Alert Name \t User Name \t Frequency \t Alert Event");
using (SPSite tmpSite = new SPSite(site))
{
using (SPWeb tmpWeb = tmpSite.OpenWeb(web))
{
SPList tmpList = tmpWeb.Lists[list];
foreach (SPAlert tmpAlert in tmpWeb.Alerts)
{
if (tmpAlert.List.Title == tmpList.Title)
{
SW.WriteLine(tmpWeb.Url + "/" + tmpList.RootFolder.Url + "\t" + tmpAlert.Title + "\t" + tmpAlert.User.Name + "\t" + tmpAlert.AlertFrequency + "\t" + tmpAlert.EventType.ToString());
alertCounter++;
}
}
}
}
//Close the File object
SW.Close();
//Display the message to the user
Console.WriteLine("Found {0} Alerts! Report has been generated! Press a key to Exit.", alertCounter);
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
System.Diagnostics.EventLog.WriteEntry("Get Alerts for List:", ex.Message);
Console.ReadLine();
}
}
}
}
Output? CSV file like the below screen:
You can Retrieve All alerts created on a SharePoint list or Library using PowerShell also. Refer my post : Create – Edit – Find – Delete SharePoint Alerts using PowerShell