How to send master page default to all pages from root page to all the pages in the portal. And edit only one master page html and Css code.

2 Answers 2


If publishing is enabled, you can simply set the master page in the root site collection, and push it down to all subsites: Site Master Page Settings

Code will be required if publishing is not enabled, or if you need to deploy to multiple site collections. Here is an example using CSOM (only updates a single web):

using (var clientContext = new ClientContext(url))
    var web = clientContext.Web;
    ctx.Load( ctx.Site, s => s.ServerRelativeUrl);
    var masterUrl = String.Format("{0}/_catalogs/masterpage/my.master", clientContext.Site.ServerRelativeUrl);
    web.MasterUrl = masterUrl;
    web.CustomMasterUrl = masterUrl;

Here is an example using JSOM instead of CSOM (ignore the title, it is JSOM), and here is an example that uses an Auto-Hosted App to set the masterpage. Edits will be needed in all three to iterate through all the webs (and site collections, if necessary). The example with the Autohosted App will need to have the permissions changed to Tenant Full Control, if you have multiple site collections (or you'll have to deploy in each site collection).

  • And how Enable Publishing ?
    – Grzegorz Z
    Commented May 15, 2014 at 13:19
  • 1
    First enable the Publishing Infrastructure in Site Collection features, then enable Publishing in the Site Features.
    – wjervis
    Commented May 15, 2014 at 13:22
  • 1
    Only an admin can enable site/site collection features, as well as set the master page.
    – wjervis
    Commented May 15, 2014 at 14:21
  • 1
    You'll either have to check in the master page, or make it so that users with view permissions can see checked out files in the Master Page gallery.
    – wjervis
    Commented May 15, 2014 at 19:09
  • 1
    Go to Site Settings, and find Master Page Gallery. Or, append the site url with the following: /_catalogs/masterpage
    – wjervis
    Commented May 16, 2014 at 13:53

If i understand your problem then this might be the solution:

You can upload your masterpage to GLOBAL root folder in 14/15 hive and CSS to layouts folder.

And at site collection write a feature to add that masterpage(from 14/15 hive) to the master page gallery .

In this way, any changes applied to Masterpage in GLOBAL folder will be applied to all site.

  • And isn't any defoult preperation on Sharepoint ? I must put this on the phisical Server ?
    – Grzegorz Z
    Commented May 15, 2014 at 12:25
  • 1
    No. You have do this by custom solution. Otherwise the changes will be reflected on only site or site collection.
    – Aanchal
    Commented May 15, 2014 at 12:27
  • But how can I do it whot I must prepere ? i want to do it for all site collection.
    – Grzegorz Z
    Commented May 15, 2014 at 17:46

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.