SharePoint gives some inbuilt functionality to create and manage alerts in lists & Libraries by using alert me option. It can also be done by code as shown below:
using (SPSite oSite = new SPSite("http://servername"))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPUser oUser = oWeb.SiteUsers["domain name\\username"];
SPAlert oListAlert = oUser.Alerts.Add();
{
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;
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;
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
oListAlert.Update(false);
oListAlert.Update(false);
//Dispose unused objects
oListAlert = null;
oUser = null;
}
}
oListAlert = null;
oUser = null;
}
}
No comments:
Post a Comment