All things Xamarin, SharePoint, and .NET related
Programmatically change theme of newly created site

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);

}

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny