Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
       }
   }
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted
  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

share|improve this answer
    
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 May 8 '12 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. –  C. Marius - MVP May 8 '12 at 20:53
    
I may have to go via the SPAudit route then - thanks for your help. –  Perplexed May 9 '12 at 14:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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