SharePoint: Web Provisioned Event Scope

The Scope of a Web Provisioned event is very important. It determines whether the event is added to SPSite.EventReceivers or SPWeb.EventReceivers collection.

Consider the following code:
using (SPSite site = new SPSite("SiteUrl"))
{
    SPWeb web = site.RootWeb;
    web.EventReceivers.Add(SPEventReceiverType.WebProvisioned, "NY.Publishing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4005dbc2d517460e", "NY.Publishing.EventReceivers.ClientSiteWebEventReceiver.ClientSiteWebEventReceiver");   
    web.Update();
}
As can be seen the Web Provisioned event is added to SPWeb.EventReceivers collection. What this means is that if a site is created under the root site collection, then this Web Provisioned event is called. However, the event will only be called for sub sites directly under root site. For example, suppose we have a site collection named "A". Now we create a sub site named "B" under "A". Then above web provisioned event will be called. Now if we create a sub site under "B" named "C", then the event will not be called. If we have a requirement where we need to call the web provisioned 
event for all sub sites irrespective of the hierarchy, then we need to add the event to SPSite.EventReceivers collection.
profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+