1

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
       }
   }

1 Answer 1

1
  1. try adding Synchronous in the Elements.xml to ensure operations do not run in separated threads.
  2. Make sure you check for the properties.Web!=null to make sure you actually get the site successfully created.
  3. No need to use SPWeb web= site.OpenWeb again, rather use directly properties.Web. Besides do use Disposable pattern when instiantiating new SPWeb, e.g. put in a using {}.

Hope it helps, C:\Marius

3
  • thanks that helped. The issue was that I was opening the web as apposed to using the properties.web. However, it now gives me an error "Update() cannot be called until all alert properties are set." It looks like it will not work without the newAlert.List assigned :( Meaning I cannot achieve what I am attempting to do :S
    – Perplexed
    Commented May 8, 2012 at 20:46
  • You do need to set the LIST property because your alert is of type SPAlertType.List but on the other hand there a only 2 types available. Commented May 8, 2012 at 20:53
  • I may have to go via the SPAudit route then - thanks for your help.
    – Perplexed
    Commented May 9, 2012 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.