Article ID: 936760 - Last Review: May 1, 2008 - Revision: 2.0

The URLs of alerts in e-mail notifications that you receive are incorrect after the URL of a Web application for a site in Windows SharePoint Services 3.0 or in SharePoint Server 2007 changes

Expand all | Collapse all

SYMPTOMS

You create one or more alerts for a list or for a document library in a site in Microsoft Windows SharePoint Services 3.0 or in Microsoft Office SharePoint Server 2007. In scenarios in which the URL of the Web application for the site changes, the URLs in the body of the e-mail notifications that you receive are incorrect. The URLs are still the old URL.

CAUSE

This issue occurs because URLs of alerts are stored as absolute URLs in the content database. Therefore, if the URL of the Web application changes, the URL of the alert is still the old URL. For example, this issue occurs if one of the following conditions is true:
  • The host name changed.
  • The port that the Web application uses changed.
  • The name of the server changed.

WORKAROUND

To work around this issue, resave each alert. You do not have to make any changes to the alert before you resave it. To resave an alert, follow these steps:
  1. Connect to the home page of the site, click Welcome UserName at the top of the page, and then click My Settings.
  2. Click My Alerts.
  3. On the "My Alerts on this Site" page, click an alert.
  4. On the Edit Alert page, resave the alert. To do this, click OK. You do not have to make any changes to the alert before you resave it.
This procedure updates the URL of the alert in the content database. The URL is updated to use the current URL of the site. After you perform this procedure, e-mail notifications that you receive will contain the correct URLs.

You can also work around this issue by using the new stsadm -o updatealert command. This command was released in the SharePoint Administration Toolkit. For more information and to download the toolkit, visit one of the following Microsoft Web sites, depending on the version of Windows SharePoint Services that you are running.

SharePoint Administration Toolkit x64
http://www.microsoft.com/downloads/details.aspx?FamilyId=F8EEA8F0-FA30-4C10-ABC9-217EEACEC9CE&displaylang=en (http://www.microsoft.com/downloads/details.aspx?FamilyId=F8EEA8F0-FA30-4C10-ABC9-217EEACEC9CE&displaylang=en)
SharePoint Administration Toolkit x86
http://www.microsoft.com/downloads/details.aspx?FamilyId=263CD480-F6EB-4FA3-9F2E-2D47618505F2&displaylang=en (http://www.microsoft.com/downloads/details.aspx?FamilyId=263CD480-F6EB-4FA3-9F2E-2D47618505F2&displaylang=en)
For more information, see the "Microsoft SharePoint Administration Toolkit" white paper. To do this, visit the following Microsoft Web site:
http://go.microsoft.com/fwlink/?LinkId=117212&clcid=0x409 (http://go.microsoft.com/fwlink/?LinkId=117212&clcid=0x409)

MORE INFORMATION

Administrators can programmatically update the URL of every alert that is created in a site collection. The following sample code updates the URLs of all alerts in a site collection.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;

namespace V3FixAlertsSiteUrl
{
    class V3FixAlertsSiteUrl
    {
        static void Main(string[] args)
        {
            string strSiteCollection = string.Empty;

            // First (and only) argument is the URL to the Site Collection
            if (args.Length > 0)
            {
                strSiteCollection = args[0];

                try
                {
                    using (SPSite spsitecol = new SPSite(strSiteCollection))
                    {
                        using (SPWeb sprootweb = spsitecol.RootWeb)
                        {
                            ListAndFixAlerts(sprootweb);
                        } // using sprootweb
                    } // using spsitecol
                }
                catch (System.IO.FileNotFoundException ioex)
                {
                    Console.WriteLine("Could not access Site Collection: {0}", ioex.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("An unexpected error occurred: {0}", ex.Message);
                } // try
            }
            else
                Console.WriteLine("No Site Collection URL was specified.");

        }
        //Enumerates all Alerts present on a Site Collection and modifies them
        //so that wrong information (for example, in the SiteUrl column) is corrected.
        static void ListAndFixAlerts(SPWeb spweb)
        {
            Console.WriteLine("\n{0} Alert(s) for site: {1} ({2})", spweb.Alerts.Count, spweb.Title, spweb.Url);

            foreach (SPAlert alert in spweb.Alerts)
            {
                try
                {
                    Console.WriteLine(" {2} Alert \"{0}\" for user \"{1}\" \n  (Id: {3})\n", alert.Title, (alert.User != null ? alert.User.Name : "<unknown>"), alert.AlertFrequency.ToString(), alert.ID.ToString());

                    alert.Properties["siteUrl"] = spweb.Site.Url;
                    if (!String.IsNullOrEmpty(alert.Properties["MobileUrl"]))
                        alert.Properties["MobileUrl"] = SPMobileUtility.GetApplicationPath(spweb);

                    try
                    {
                        alert.Update();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(" -> Error changing Alert. {0}", ex.Message);
                    } // inner try
                }
                catch (Exception ex)
                {
                    Console.WriteLine(" An unexpected error occurred while accessing the Alert object: {0}", ex.Message);
                } // outer try
            } // foreach alert

            //Handle all Sub-Webs recursively.
            if (spweb.Webs.Count > 0)
            {
                for (int i = spweb.Webs.Count - 1; i >= 0; i--)
                {
                    using (SPWeb spsubweb = spweb.Webs[i])
                    {
                        ListAndFixAlerts(spsubweb);
                    } // using spsubweb
                } //for subwebs
            } //if has subweb
        }

    }
}

APPLIES TO
  • Microsoft Windows SharePoint Services 3.0
Keywords: 
kbtshoot kbexpertiseinter kbprb KB936760
 

Article Translations