Using CSOM and c#, I would like to change the master-page from Seattle to Oslo. Can anybody help me?


Use the MasterUrl and CustomMasterUrl properties of Web:

using (var ctx = new ClientContext( url ))
    var web = ctx.Web;
    var masterPageUrl = String.Format( "{0}/_catalogs/masterpage/oslo.master", ctx.Web.ServerRelativeUrl );

    web.MasterUrl = masterPageUrl;
    web.CustomMasterUrl = masterPageUrl;

    ctx.Load( web );
| improve this answer | |

Changing Master page is very easy in SharePoint Using CSOM, we can give the Master Page URL in the web masterpage property, for reference u can check this link : apply-master-page-using-csom

| improve this answer | |
  • is there a way to enforce "reset all subsites to use same master page" using CSOM? – Vignesh Subramanian Oct 7 '15 at 9:30

For SharePoint Online - use Visual Studio. NuGet the following package into your winform or console app: Micrososft.SharePointOnline.CSOM

Then use code similar to the below:

using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ChangeMaster
public partial class ChangeMaster : System.Windows.Forms.Form
    public ChangeMaster()

    private SecureString ConvertToSecureString(string password)
        if (password == null)
            throw new ArgumentNullException("password");

        var securePassword = new SecureString();

        foreach (char c in password)

        return securePassword;
    private void button1_Click(object sender, EventArgs e)
        Microsoft.SharePoint.Client.ClientContext cc = new Microsoft.SharePoint.Client.ClientContext("https://yourco.sharepoint.com/");
        SecureString secstring = ConvertToSecureString("yourpassword");
        SharePointOnlineCredentials creds = new SharePointOnlineCredentials("user@yourco.onmicrosoft.com", secstring);

        // The SharePoint web at the URL.
        Web web = cc.Web;

        // We want to retrieve the web's properties.

        // Execute the query to the server.

        var a = web.Title; // For debug checks.
        var master = web.CustomMasterUrl; // For debug checks.
        web.CustomMasterUrl = "/_catalogs/masterpage/seattle.master"; // Or the original page desired.
        web.MasterUrl = "/_catalogs/masterpage/seattle.master";
        // Execute the query to server.


| improve this answer | |

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.