{"id":54,"date":"2010-04-30T09:13:52","date_gmt":"2010-04-30T14:13:52","guid":{"rendered":"http:\/\/www.johndhutton.com\/?p=54"},"modified":"2015-07-06T12:23:05","modified_gmt":"2015-07-06T17:23:05","slug":"programmatically-change-theme-of-newly-created-site","status":"publish","type":"post","link":"https:\/\/www.johndhutton.com\/?p=54","title":{"rendered":"Programmatically change theme of newly created site"},"content":{"rendered":"<p>Add Event Reciever for WebProvisioned:<\/p>\n<p>Right Click on Project-&gt;Add-.New Item&#8230;-&gt;Event Reciever and lets call it WebProvisionedEvent<\/p>\n<p><a href=\"http:\/\/www.johndhutton.com\/wp-content\/uploads\/2012\/04\/EventReciever-WebProvisioned.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-55\" title=\"EventReciever-WebProvisioned\" src=\"http:\/\/www.johndhutton.com\/wp-content\/uploads\/2012\/04\/EventReciever-WebProvisioned-300x207.jpg\" alt=\"\" width=\"300\" height=\"207\" srcset=\"https:\/\/www.johndhutton.com\/wp-content\/uploads\/2012\/04\/EventReciever-WebProvisioned-300x207.jpg 300w, https:\/\/www.johndhutton.com\/wp-content\/uploads\/2012\/04\/EventReciever-WebProvisioned.jpg 955w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now select &#8220;A site was provisioned&#8221;<\/p>\n<p><a href=\"http:\/\/www.johndhutton.com\/wp-content\/uploads\/2012\/04\/EventReciever-WebProvisioned-SiteProvisioned.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-56\" title=\"EventReciever-WebProvisioned-SiteProvisioned\" src=\"http:\/\/www.johndhutton.com\/wp-content\/uploads\/2012\/04\/EventReciever-WebProvisioned-SiteProvisioned-300x214.jpg\" alt=\"\" width=\"300\" height=\"214\" srcset=\"https:\/\/www.johndhutton.com\/wp-content\/uploads\/2012\/04\/EventReciever-WebProvisioned-SiteProvisioned-300x214.jpg 300w, https:\/\/www.johndhutton.com\/wp-content\/uploads\/2012\/04\/EventReciever-WebProvisioned-SiteProvisioned.jpg 709w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Change WebProvisioned method to this<\/p>\n<pre class=\"prettyprint lang-cpp\">public override void WebProvisioned(SPWebEventProperties properties)\r\n{\r\n   &#47;&#47;newly created site\r\n   SPWeb childSite = properties.Web;\r\n   &#47;&#47;Get Parent\r\n   SPWeb topSite = childSite.ParentWeb;\r\n   &#47;&#47;Set themes to same as parent\r\n   childSite.MasterUrl = topSite.MasterUrl;\r\n   childSite.CustomMasterUrl = topSite.CustomMasterUrl;\r\n   childSite.AlternateCssUrl = topSite.AlternateCssUrl;\r\n   childSite.SiteLogoUrl = topSite.SiteLogoUrl;\r\n\r\n   &#47;&#47;Set child site to use Parent&#39;s Navigation in Top Nav\r\n   childSite.Navigation.UseShared = true;\r\n\r\n   &#47;&#47;Update\r\n   childSite.Update();\r\n\r\n   base.WebProvisioned(properties);\r\n\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Add Event Reciever for WebProvisioned: Right Click on Project-&gt;Add-.New Item&#8230;-&gt;Event Reciever and lets call it WebProvisionedEvent Now select &#8220;A site was provisioned&#8221; Change WebProvisioned method to this public override void WebProvisioned(SPWebEventProperties properties) { &#47;&#47;newly created site SPWeb childSite = properties.Web; &#47;&#47;Get Parent SPWeb topSite = childSite.ParentWeb; &#47;&#47;Set themes to same &hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4],"tags":[],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-sharepoint","category-sharepoint-2010"],"_links":{"self":[{"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=54"}],"version-history":[{"count":25,"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":404,"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=\/wp\/v2\/posts\/54\/revisions\/404"}],"wp:attachment":[{"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndhutton.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}