Search

  • Home
  • Screencasts
  • Speaking
  • Downloads
  • Consulting Services
Browsing: / Home / 2010 / August / 15 / Creating custom list alert templates in SharePoint 2010
Print Email Shortlink

Creating custom list alert templates in SharePoint 2010

By Yaroslav Pentsarskyy on August 15, 2010 in MOSS, sharepoint, sharepoint 2010
Tweet

SharePoint 2010 allows you to create custom alert templates per list, meaning you can customize what’s going to show up in your SPList alert body.

In this example I won’t focus how you can actually edit the alert CAML – you can figure it out based on existing list of templates, let`s see what`s involved in creating a new alert template and assigning it to the list:

1. Create a new Visual Studio 2010 SharePoint solution.

2. Map a TEMPLATES folder in your solution directory and create a new folder underneath it called XML. This XML folder will contain an XML file that will define your alerts.

3. Create a new file in sub folder (project specific name) inside XML folder in your solution and add XML File into a sub folder.

4. Navigate to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML on your file system and open alerttemplates.xmlthis is out-of-the-box alert definition that you should not modify. Take a loot at the structure of the file and how each alert is defined.

5. Copy alert definition of the list type that closely resembles what you want your new alert to look like ad paste it into your solutions custom alert XML file. If we were to copy generic list template – everything including the XML below would have to be copied:

<AlertTemplate Type="List" 
Name="SPAlertTemplateType.GenericList">
</AlertTemplate>

6. Make any adjustments to the custom alert CAML (this is something you will have to figure out based on your needs).

7. Create a new site scoped feature which will add our custom alert template to the list of your choice and not to any other list on the site.

8. Add a receiver to the feature and in FeatureActivated method place the following code:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPSite site = properties.Feature.Parent as SPSite;
    XmlDocument xmlDoc = new XmlDocument();
    // The path to your alert templates
    xmlDoc.Load(SPUtility.GetGenericSetupPath(@"XML\YourProject")
+ "YourAlertTemplates.xml");
    // The list you want to have custom alert template
    SPList list = site.RootWeb.Lists["YourList"];
    SPAlertTemplate template = new SPAlertTemplate();
    template.Xml = xmlDoc.InnerXml;
    template.Name = "YourAlertTemplate";
    list.AlertTemplate = template;
    list.ParentWeb.AllowUnsafeUpdates = true;
    list.Update();
}

Above is going to take care of loading the template and assigning it to the list.

Now when this code is executed and template loaded to the list – new alert that are triggered with the template are going to come with the definition you have specified in your custom alert template file.

Good Luck!

Share this on: Mixx Delicious Digg Facebook Twitter
alertcustom list alertssharepointsharepoint alert
  • Related Stories
  • Most Popular
  • How to: avoid duplicate load of jQuery, or else!
  • How to: automatically package your SharePoint 2013 branding solutions with design manager
  • How To: improve SharePoint/Office 365 site SEO with page keywords and meta description
  • SharePoint 2013 training for developers
  • How to: setting property bag properties on a web in SharePoint online
  • Enabling geolocation field in your SharePoint 2013 list using an app
  • Enabling geolocation field in your SharePoint 2013 list using an app
  • SharePoint Branding: add a handy function to allow users show/hide quick launch bar
  • Add SharePoint 2010 quick launch toggle on/off feature
  • Modify out of the box and custom SharePoint 2010 workflow forms
  • Creating WCF service in SharePoint 2010
  • SharePoint 2010 Branding: defining new Content Query roll up rendering template
← Previous Next →

Just Released! My SharePoint 2013 Book

My SharePoint books & DVD

Copyright © 2013 sharemuch.com.

Powered by WordPress and News.