none
how to register custom alert template using SharePoint 2010 feature in c# code

    Question

  • Hi, 

    I have created a custom alert template, my only proble is how can I use it to any Sharepoint 2010 site Ive created to all the object and list that has an active email alert. Is it possible to use feature using a c# code? please help me on this at least a sample code. Any help is appreciated.

    Thanks. :)

    Sunday, March 10, 2013 8:34 AM

Answers

  • Hi,

    Check out the below blogs.

    See the belwo blog, how to create a Visual stuido solution project for custom alert template.

    http://blog.zebsadiq.com/post/SharePoint-2010-custom-alert-template.aspx

    1> step-1: Add a new xml file to this folder called ‘custom_alerttemplates.xml’. Open the alerttemplates.xml  file from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML\ , copy all of its contents into your newly created custom_alertstemplates.xml file.

    2> step-2: Add a class file and write the code for modfying the properties, for this you have to inherit the class from IAlertNotifyHandler interface.

    http://12hive.wordpress.com/2010/08/03/sharepoint-customizing-alert-emails-using-ialertnotifyhandler/

    https://sites.google.com/a/tolvunord.is/sharepoint/home/sharepoint/customalerthandler

    3> step-3:  Refer the section "Deploying your custom alert template file" in the below blog.

    http://blog.zebsadiq.com/post/SharePoint-2010-custom-alert-template.aspx

    Saturday, March 16, 2013 1:37 AM
  • This code below works for me. Hope it helps! :)

    using(SPSite oSiteCollection = new SPSite(siteId))

    {

    SPWebCollection collWebs = oSiteCollection.AllWebs;

    XmlDocument xmlDoc = new XmlDocument();

    // The path to custom alert templates //

    xmlDoc.Load(

    SPUtility.GetGenericSetupPath(@"TEMPLATE\XML\") + "custom_alerttemplates.xml");

    // ---------------------------------- //

    foreach (SPWeb oWebsite in collWebs)

    {

    SPListCollection oWebLists = oWebsite.Lists;

    foreach (SPList list in oWebLists)

    {

    // updates the list alert templates to custom alert templates //

    SPAlertTemplate template = new SPAlertTemplate();

    template.Xml = xmlDoc.InnerXml;

    // Get the specific alert template name for the list //

    AlertTemplateNames templateName = new AlertTemplateNames();

    template = templateName.GetAlertTemplateName(list.BaseTemplate);

    // ------------------------------------------------- //

    list.AlertTemplate = template;

    list.ParentWeb.AllowUnsafeUpdates =

    true;

    list.Update();

    // ---------------------------------------------------------- //

    // Converts all subscribed or existing alerts of the list to the custom alert template //

    foreach (SPAlert alert in list.ParentWeb.Alerts)

    {

    if (alert.ListID == list.ID)

    {

    alert.AlertTemplate = list.AlertTemplate;

    alert.Update();

    }

    }

    • Marked as answer by Debugger_09 Wednesday, April 10, 2013 4:58 PM
    Wednesday, April 10, 2013 4:58 PM

All replies

  • Hi,

    Refer the following blog .

    http://blog.zebsadiq.com/post/SharePoint-2010-custom-alert-template.aspx

    http://neganov.blogspot.in/2011/08/custom-alerts-in-sharepoint-templates.html

    ------------------------------------------------------------------------------------------------------------------------------------

    If you find the reply to the solution to your question,Please click as "Alternate TextMark As Answer" 

    Monday, March 11, 2013 3:23 AM
  • Hi,

    Refer the following blog .

    http://blog.zebsadiq.com/post/SharePoint-2010-custom-alert-template.aspx

    http://neganov.blogspot.in/2011/08/custom-alerts-in-sharepoint-templates.html

    ------------------------------------------------------------------------------------------------------------------------------------

    If you find the reply to the solution to your question,Please click as "Alternate TextMark As Answer" 

    Thanks for providing the bligs it helped me alot to start the development. my only problem is that I have to customize all the objects or template of alert email. For this how can I code it on Visual studio feature. should I update it individually? 


    Friday, March 15, 2013 6:21 PM
  • Hi,

    Check out the below blogs.

    See the belwo blog, how to create a Visual stuido solution project for custom alert template.

    http://blog.zebsadiq.com/post/SharePoint-2010-custom-alert-template.aspx

    1> step-1: Add a new xml file to this folder called ‘custom_alerttemplates.xml’. Open the alerttemplates.xml  file from C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML\ , copy all of its contents into your newly created custom_alertstemplates.xml file.

    2> step-2: Add a class file and write the code for modfying the properties, for this you have to inherit the class from IAlertNotifyHandler interface.

    http://12hive.wordpress.com/2010/08/03/sharepoint-customizing-alert-emails-using-ialertnotifyhandler/

    https://sites.google.com/a/tolvunord.is/sharepoint/home/sharepoint/customalerthandler

    3> step-3:  Refer the section "Deploying your custom alert template file" in the below blog.

    http://blog.zebsadiq.com/post/SharePoint-2010-custom-alert-template.aspx

    Saturday, March 16, 2013 1:37 AM
  • This code below works for me. Hope it helps! :)

    using(SPSite oSiteCollection = new SPSite(siteId))

    {

    SPWebCollection collWebs = oSiteCollection.AllWebs;

    XmlDocument xmlDoc = new XmlDocument();

    // The path to custom alert templates //

    xmlDoc.Load(

    SPUtility.GetGenericSetupPath(@"TEMPLATE\XML\") + "custom_alerttemplates.xml");

    // ---------------------------------- //

    foreach (SPWeb oWebsite in collWebs)

    {

    SPListCollection oWebLists = oWebsite.Lists;

    foreach (SPList list in oWebLists)

    {

    // updates the list alert templates to custom alert templates //

    SPAlertTemplate template = new SPAlertTemplate();

    template.Xml = xmlDoc.InnerXml;

    // Get the specific alert template name for the list //

    AlertTemplateNames templateName = new AlertTemplateNames();

    template = templateName.GetAlertTemplateName(list.BaseTemplate);

    // ------------------------------------------------- //

    list.AlertTemplate = template;

    list.ParentWeb.AllowUnsafeUpdates =

    true;

    list.Update();

    // ---------------------------------------------------------- //

    // Converts all subscribed or existing alerts of the list to the custom alert template //

    foreach (SPAlert alert in list.ParentWeb.Alerts)

    {

    if (alert.ListID == list.ID)

    {

    alert.AlertTemplate = list.AlertTemplate;

    alert.Update();

    }

    }

    • Marked as answer by Debugger_09 Wednesday, April 10, 2013 4:58 PM
    Wednesday, April 10, 2013 4:58 PM