In SharePoint we can use the AlertMe option present within a List or a Document Library to create one or more alerts for sending notifications to a set of users based on different events. SharePoint provides out of the box options for creating and managing alerts.
We can also create these Alerts programmatically using the SharePoint object model. For this we need to use the SPAlert class..
Following code snippet shows how to create SharePoint Alert programmatically:
using (SPSite oSite = new SPSite("http://servername"))
using (SPWeb oWeb = oSite.OpenWeb())
SPUser oUser = oWeb.SiteUsers["domain name\\username"];
SPAlert oListAlert = oUser.Alerts.Add();
//Define the type of object to which alert is applied
oListAlert.AlertType = SPAlertType.List;
//Gets or sets the List or Document Library to which alert is applied
oListAlert.List = oWeb.Lists["List_Name"];
//Define the Event type to which alert is applied
oListAlert.EventType = SPEventType.All;
//Set the time interval for sending alert.
oListAlert.AlertFrequency = SPAlertFrequency.Immediate;
//Passing true to Update method will send alert confirmation mail
//Dispose unused objects
oListAlert = null;
oUser = null;