1

I applicate the master page to the parent site and to all my subsites. In fact the master page was not applicated to all the subsite. this is the hierarchy:

-parent site: type publishing  -sub site1: wikisite
                               -subsite 2:team site 
                               -subsite 3: publishing

I only found the subsite 3 have the same master page as parent site? So is teher a solution how to force all the subsite to take the parent's master page

0

There is. Either by C#:

var web = SPContext.Current.Web; //you can get that in a different way
var rootWeb = web.Site.RootWeb; //You root web site
web.MasterUrl = rootWeb.MasterUrl;
web.CustomMasterUrl = rootWeb.CustomMasterUrl;
web.Update();

or by PowerShell:

$web = Get-SPWeb http://wikisiteURL
$rootWeb = Get-SPWeb http://parentsiteURL
$web.MasterUrl = $rootWeb.MasterUrl;
$web.CustomMasterUrl = $root.CustomMasterUrl;
$web.Update();

Throw in a for-each for web.Site.AllWebs and you will be able to do that for all the subsites. Don't forget to properly dispose of the SPWeb objects as well.

| improve this answer | |
  • $rootWeb = Get-SPWeb $web.ParentWeb.Url a have erroe on this , and $rootWeb.MasterUrl= give the seattle – Imen Turki Mar 4 '16 at 10:50
  • Use this instead: $rootWeb = Get-SPWeb $web.Site.RootWeb; and then $rootWeb.MasterUrl should display your custom master page. – Paul Strupeikis Mar 4 '16 at 11:04
  • Sorry, I mistyped a bit of code. This is how it needs to look like: $rootWeb = $web.Site.RootWeb; Your code should work. Does it give any error? – Paul Strupeikis Mar 4 '16 at 11:34
  • know ok , it works fine – Imen Turki Mar 4 '16 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.