SharePoint Alert customization
Referred URL
http://sridharu.blogspot.com/2008/12/sharepoint-alert-customization.html
You can create one or more alerts for a list or document library in a SharePoint site. When creating alerts you have option of what event and when to get notified. Alerts can be managed by Administrators or Users. SharePoint object model provides methods to manage Alerts programmatically.
SPAlert class provides details on alert like alert frequency, alert type,user who created the alert. This class also provides a method to update alert details. Following code snippet shows how to create SharePoint Alert programmatically:
using (SPSite site = new SPSite("http://servername"))
{
using (SPWeb web = site.OpenWeb())
{
SPUser user = web.SiteUsers["domain name\\username];
SPAlert newAlert = user.Alerts.Add();
newAlert.AlertType = SPAlertType.List;
newAlert.List = web.Lists["List Name"];
newAlert.EventType = SPEventType.All;
newAlert.AlertFrequency = SPAlertFrequency.Immediate;
//passing true to Update method will send alert confirmation mail
newAlert.Update(false);
}
}
SharePoint stores the alert information like web application URL and List URL in content database. Because of this, the links inside alert mail will break if web application URL or List URL is changed. To fix this user need to update the alert manually from alert manager or Administrator can run a script to update alerts. Refer this link for more details on this issue.
Alert mails can be customized in two ways:
Approach 1
You can customize the Alert tempaltes of WSS. Alert tempaltes are located in
"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\XML\AlertTemplates.xml"
Following link has lot of details on this approach:
http://blogs.msdn.com/sharepointdeveloperdocs/archive/2007/12/07/customizing-alert-notifications-and-alert-templates-in-windows-sharepoint-services-3-0.aspx
Approach 2
You can also customize alert mail format by implementing IAlertNotifyHandler interface. Following Microsoft KB article has details on this:
http://support.microsoft.com/kb/948321/en-us
How to debug custom alert handlers
Alerts are generated by WSS timer job. Time job reads the event log and sends the alert. So to debug custom alert handlers you need to attach timer process to debugger (OWSTIMER.exe).
0 comments