I am trying to get subsites of my parent site to inherit the same masterpage as their parent. I have a feature stapled to all the default site templates that contain my master page.
I have created a Event Receiver called ChildSiteInit. It has the following code:
using Microsoft.SharePoint;
namespace SP_Intranet.ChildSiteInit
{
public class ChildSiteInit : SPWebEventReceiver
{
public override void WebProvisioned(SPWebEventProperties properties)
{
SPWeb childSite = properties.Web;
SPWeb topSite = childSite.Site.RootWeb;
childSite.MasterUrl = topSite.MasterUrl;
childSite.CustomMasterUrl = topSite.CustomMasterUrl;
childSite.AlternateCssUrl = topSite.AlternateCssUrl;
childSite.SiteLogoUrl = topSite.SiteLogoUrl;
childSite.Update();
}
}
}
This is taken from Inside Microsoft SharePoint 2010 (direct copy bar the namespace).
It is displayed in my feature and the feature is deployed. The feature is deployed at site collection level.
When I create a new sub site the parent masterpage is not inherited.
Updated code removing usings