Customize WSS Alert template

Customize WSS Alert template

There are two way to customize wss alert template
(1) Modify the template file
the default template file is 12\TEMPLATE\XML\alerttemplates.xml. it's a CAML file. You can rewrite it and use stsadm to deploy it
STSADM -o updatealerttemplates -url -filename
(2) Using a class inherit for interface IAlertNotifyHandler. Put the implement of this class into custom alert template file, and then you can use stsadm to deploy it

The advantage of the first method is can to need deal with alert logic(it is implemented by SharePoint), but the CAML is very complex, and you can't edit complex logic.
The second method is very agility, but some feature of the alert template will lost(such as the email which alerts modified item can display which words were changed, which words were newly added.)

This paragraph written by WSS SDK group will give you a a minute description about this topic
http://blogs.msdn.com/sharepointdeveloperdocs/archive/2007/12/07/customizing-alert-notifications-and-alert-templates-in-windows-sharepoint-services-3-0.aspx



Instead of stsadm, you can also use code to deploy alert template, like this:

string templateName="customTemplate1";
// Get the template of the web server
SPAlertTemplateCollection ats = new SPAlertTemplateCollection((SPWebService)( base.GetCurrentSPSite().WebApplication.Parent));

//add or modify the template
SPAlertTemplate t = ats[templateName];

if( t == null )
t = ats.Add();

t.Name = templateName;
t.Xml = xmlDoc.InnerXml;

t.Update();

// Set the alert template for each list separately
SPList list = someList ;
list.AlertTemplate = ats[templateName];
list.ParentWeb.AllowUnsafeUpdates = true;
list.Update();

0 comments: