April 30

Programmatically change theme of newly created site

Add Event Reciever for WebProvisioned:

Right Click on Project->Add-.New Item…->Event Reciever and lets call it WebProvisionedEvent

Now select “A site was provisioned”

Change WebProvisioned method to this

public override void WebProvisioned(SPWebEventProperties properties)
{
   //newly created site
   SPWeb childSite = properties.Web;
   //Get Parent
   SPWeb topSite = childSite.ParentWeb;
   //Set themes to same as parent
   childSite.MasterUrl = topSite.MasterUrl;
   childSite.CustomMasterUrl = topSite.CustomMasterUrl;
   childSite.AlternateCssUrl = topSite.AlternateCssUrl;
   childSite.SiteLogoUrl = topSite.SiteLogoUrl;

   //Set child site to use Parent's Navigation in Top Nav
   childSite.Navigation.UseShared = true;

   //Update
   childSite.Update();

   base.WebProvisioned(properties);

}