I'm reading "How to create a custom e-mail alert handler in Microsoft Office SharePoint Server" right now and as follow the how-to-guide, I found out that every time you need to modify alerts you have to go through the whole process again (from registering the dll to the GAC to restarting the Windows SharePoint Services Timer service). I was wondering if you can create a feature to do all this. When the feature is activated the custom alert template file will be used. If the feature is deactivated, it will revert to the original file. Is this possible? Can somebody show me how to do this?

  • Can you explain how your alert is meant to take effect? I.e., does it only apply to only a named list, or does apply to all lists of a given type (document libraries) in the site? Is it supposed to apply to new lists of that type as well?
    – Dave Wise
    Commented Aug 24, 2011 at 15:45
  • @Dave: What I was trying to achieve is to have a notification counter. How many new postings were done, new announcements, new discussions, etc. (all alerts set by the user). This counter will then be saved as a list in "MySite" for that particular user. This will be used in a web part that will display all alert notifications. The web part will be something like this: NEW Alerts!! 1 Discussion(s) 1 Announcement(s) Commented Aug 28, 2011 at 5:24

1 Answer 1


I have achieved this with my custom alerts using nothing but a feature and a feature reciever.

NB: Upgrading your solution package using STSADM (or deploying directly from Visual Studio 2010) will automatically upgrade all your assemblies and provisioned files and recycle your app pool, so all you need to do is connect your custom alert tempates. Here's how:

Step 1: Inside your Visual Studio solution, right click your project and select "Add -> SharePoint Mapped Folder" then select the "TEMPLATE\XML" folder. Place your custom alert template files in here (they should be XML files).

That takes care of deploying your files to the SharePoint root, now you need to instruct SharePoint to parse these files when your feature activates....

Step 2: Inside your feature receiver, just add the following code:

SPAlertTemplateCollection alertTemplates = new SPAlertTemplateCollection((SPWebService)(siteCollection.WebApplication.Parent));

alertTemplates.InitAlertTemplatesFromFile(SPUtility.GetGenericSetupPath("TEMPLATE\\XML\\") + "CustomAlertTemplate.xml");
alertTemplates.InitAlertTemplatesFromFile(SPUtility.GetGenericSetupPath("TEMPLATE\\XML\\") + "CustomAlertTemplate_SMS.xml");

That's it!

These custom alert templates will now be available to use anywhere within your application using the following code:

// Retrieve your custom alert template.
SPAlertTemplateCollection alertTemplates = new SPAlertTemplateCollection((SPWebService)(listItem.ParentList.ParentWeb.Site.WebApplication.Parent));
SPAlertTemplate customAlertTemplate = alertTemplates["CustomAlertTemplateName"];

if (customAlertTemplate == null)
    throw new ApplicationException("The alert template \"CustomAlertTemplateName\" has not been registered.");

// Create the alert without sending a confirmation email.    
SPAlert newAlert = listItem.ParentList.ParentWeb.CurrentUser.Alerts.Add();
newAlert.Title = "Title";
newAlert.AlertTemplate = customAlertTemplate;
  • Is SPAlertTemplateCollection.InitAlertTemplatesFromFile() equivalent to this command: stsadm -o updatealerttemplates -filename "..." -url "..."? The linked article uses this to actually run custom code to generate e-mail alerts, not just register a new template file.
    – MgSam
    Commented Oct 17, 2012 at 19:51
  • Hey there I'm having the same issue, and I'm trying your way but it doesn't seem to access my xml file, all I got is an error saying :access denied Microsoft.SharePoint.SPAlertTemplateCollection.CreateOrUpdateAlertTemplates(String name, String xml) any ideas ?
    – Glolita
    Commented Apr 3, 2013 at 9:59
  • Can you provide some more details -- like the line of code that is generating the exception, and the relevant lines from your SharePoint logs? Note: SharePoint often misleadingly displays an "access denied" page in the browser even when errors occur that have nothing to do with security! On the other hand though, if the "Access denied" message is appearing in your log files, then I'd say with certainty that it realy is a permissions issue. If all else fails, try elevate privelages or run the code as a different user (i.e. using impersonation or your farm admin accout).
    – user4545
    Commented Apr 4, 2013 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.