Friday, August 29, 2008

Configuring specific alert template for a single list

Scenario:
You have a special list and you want to use unique email alert template for that list.

Solution:
You need to edit the AlertTemplates.xml file to include the new template which you want to use with a unique name and then you can programatically set this specific alert template for any particular list. Assuming you have created a new alert template in AlertTemplates.xml with the name 'AlertTemplate.SpecialList'.

Code:

using(SPSite site = new SPSite("http://localhost")){
using(SPWeb web = site.Open.RootWeb){
SPList = web.Lists["SpecialList"];

SPAlertTemplateCollection ats = new SPAlertTemplateCollection((SPWebService)(WebApplication.Parent)); 

//give appropriate values for WebApplication
list.AlertTemplate = ats["AlertTemplate.SpecialList"];
list.Update();
}
}
Article:
All about sharepoint alerts , MSDN , Pre Defined Templates

2 comments:

Anonymous,  August 16, 2010 at 4:34 PM  

Hello

Where do I run this code? In Powershell?

Sandeep August 16, 2010 at 10:23 PM  

I kept it generic , as this code need to be run only one time....

you can use it in console application / feature receiver