Apply Master Page using CSOM in SharePoint

In SharePoint we can Apply Master Pages programmatically using CSOM(Client Object Model). I have a requirement where we are using an EXE file which is build on .Net Client Object Model(CSOM). In this exe file, we wrote code to create sub sites and for that created sub sites we have to apply the master pages.

Here is the sample code for Applying master pages using CSOM.

public void ChangeGroupMasterPage()
{
 try
 {
  Site site = this.Context.Site;
  this.Context.Load(site);
  this.Context.ExecuteQuery();

  Web web = this.Context.Web;
  this.Context.Load(web);

  web.CustomMasterUrl = site.ServerRelativeURL +
      "/_catalogs/masterpage/custom.master";

  //Update the system master.
  web.MasterUrl = site.ServerRelativeURL +
      "/_catalogs/masterpage/customSystem.master";

  web.Update();
  this.Context.ExecuteQuery();
 }
 catch (Exception ex)
 {
  //Ex message log
 }
}

Hope this article is Helpful for you.
SHARE

Sudheer Gangumolu

I'm a Software Analyst / Developer / Blogger, having good experience in working with different flavors & Customization of SharePoint (i.e.,SP O365 / 2013 / 2010 / 2007) and .Net Apps. Currently, working on SharePoint 2013 / SharePoint O365. Guiding people on my technologies.

    Blogger Comment
    Facebook Comment

1 comments :

  1. I like what you guys are up too. Such intelligent work and reporting!Keep up the excellent works guys I have incorporated.
    SharePoint Online Training

    ReplyDelete