I want to set alerts for all users whenever a new subsite is created under the root site.
I am using the WebProvisioned event, but when I attempt to Update() my new alert I get an error: "There is no web named ". "A first chance exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.SharePoint.dll"
Any help appreciated, thanks.
My code is below:
public override void WebProvisioned(SPWebEventProperties properties)
{
base.WebProvisioned(properties);
if (properties.Web.ParentWeb.Name == "emerg")
{
SPSite site = new SPSite(properties.Web.Url);
SPWeb web = site.OpenWeb(properties.Web.Url);
SPAlert newAlert = web.Alerts.Add();
newAlert.AlertFrequency = SPAlertFrequency.Immediate;
newAlert.AlertType = SPAlertType.List;
newAlert.EventType = SPEventType.All;
newAlert.Title = "all alerts - " + properties.Web.Name;
newAlert.Update(false); //errors here
}
}