6

I am able to change the master page using the below code

var web = ctx.Web;
    var masterPageUrl = String.Format( "{0}/_catalogs/masterpage/filename.master", ctx.Web.ServerRelativeUrl );
    web.MasterUrl = masterPageUrl;
    web.CustomMasterUrl = masterPageUrl;
    web.Update();
    ctx.Load( web );
    ctx.ExecuteQuery();

This works fine and it changes the master page to desired file.

But the problem is after doing that i have to manually goto

"site settings" -> "goto the top level settings" -> "master page"

and then check the "Reset all subsites to inherit this site master page setting"

Is there a way to avoid this manual step and achieve this using CSOM?

1

1 Answer 1

4

Try following code.

foreach(Web child in web.Webs) {
    child.AllProperties["__InheritsCustomMasterUrl"] = true;
    child.AllProperties["__InheritsMasterUrl"] = true;
    child.Update();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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