SharePoint 2010 Alert Issue After Upgrade: Follow-Up

A while back I wrote about how alerts failed to work in SharePoint 2010 after a migration from SharePoint 2007.    Since then it appears that the blog entry I had linked to with sample code is no longer available. Sad smile 

Below is a sample console application that I used to resolve the alerts issue I experienced during the migration.  Your mileage and success may vary… and please try this in a test environment first!

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Administration;

 

namespace AlertFix

{

    class Program

    {

        static void Main(string[] args)

        {

 

            if (args.Length == 0)

            {

                Console.WriteLine("AlertFix");

                Console.WriteLine("----------------");

                Console.WriteLine("Purpose: Fix Alert issues after migration");

                Console.WriteLine("");

                Console.WriteLine("Usage: FixAlert [url] ");

                Console.WriteLine("");

                Console.WriteLine("Example: FixAlert http://WebApplication");

                return;

            }

 

            foreach (string wa in args)

            {

                using (SPSite site = new SPSite(wa))

                {

                    SPWebApplication webApp = site.WebApplication;

                    SPSiteCollection sitecollections = webApp.Sites;

 

                    foreach (SPSite siteCollection in sitecollections)

                    {

                        foreach (SPWeb web in siteCollection.AllWebs)

                        {

                            foreach (SPAlert alrt in web.Alerts)

                            {

 

                                string origTitle = alrt.Title;

                                alrt.Title = "UPDATE: " + origTitle;

                                alrt.Update();

 

                                alrt.Title = origTitle;

                                alrt.Update();

                                Console.WriteLine("Update Alert " + alrt.Title + " for " + (alrt.User!=null?alrt.User.Name:"unknown") + " on site " + web.Url);

                            }

                        }

                    }

                }

            }

        }

    }

}

So what does this do?   It forces an update to each of the alerts in a web applications by changing the alert title, doing an update, changing the title back and updating again.   After running this utility against a problem web application my alerts began to fire off as expected. 

Important notes:

  • Disable outgoing email on your SharePoint farm before running this code.  If you fail to do this your users may receive a flood of emails during this process.   Once the process is complete you can enable outgoing email.
  • If you moved your farm to a different URL during the upgrade / migration this will solve only part of your issues.  You may still experience issues with having the wrong URL in the email alerts.  To resolve this issue you will need to write code that also updates the SiteUrl property of the alert object.

0 thoughts on “SharePoint 2010 Alert Issue After Upgrade: Follow-Up”

  1. I tried this code and it did not seem to affect the alerts. Emails were still not sent. If I create a new alert they work fine but alerts created before the migration do not work after running this code. Now, this is on our test environment so the URL of the site is different than the production 2007 site. Is that maybe causing the alerts not to work or does the URL mismatch just make the URL in the email incorrect?

    Thanks…

  2. @Phong Bui – The siteurl is a key in the alerts property bag. You get to it by doing something like this:

    SPPropertyBag spprop = alert.Properties;
    spprop[“siteurl”] = “…URL TO SET…”;
    spprop.Update();

    You might also want to verify that the mobileurl property is also set to the proper URL.

Leave a Reply