Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
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
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.
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.
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:
- Connect to the home page of the site, click Welcome UserName at the top of the page, and then click My Settings.
- Click My Alerts.
- On the "My Alerts on this Site" page, click an alert.
- 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 x64SharePoint Administration Toolkit x86 For more information, see the "Microsoft SharePoint Administration Toolkit" white paper. To do this, visit the following Microsoft Web site:
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
| kbtshoot kbexpertiseinter kbprb KB936760 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate