none
system masterpage not getting updated for default pagelayouts

    Question


  • We have deactivated some of the wsp from our office 365 sites and in one of wsp code, feature deactivation logic to maps default masterpage (v4.master). This has an impact on OOB pagelayouts (pagenotfound.aspx,articleleft.aspx and others)

    I tried to map system master from site settings --> Master Page --> Applied seattle.master to system master page section. But no luck, it is still pointing to v4.master.

    Need some help or pointers to map the seattle.master to OOB pagelayouts.

    Advance Thanks!!

    Thursday, October 13, 2016 3:19 PM

All replies

  • Hi,

    Please try to use the CSOM code to set the master page. The following code snippet for your reference:

    var login = "dennis@xxx.onmicrosoft.com";
    var password = "xxxxxx";
    var securePassword = new SecureString();
    foreach (char c in password)
    {
        securePassword.AppendChar(c);
    }
    SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, securePassword);	 
    using (var ctx = new ClientContext("siteurl"))
    {	
        ctx.Credentials = onlineCredentials;
        var web = ctx.Web;
        var masterPageUrl = String.Format( "{0}/_catalogs/masterpage/seattle.master", ctx.Web.ServerRelativeUrl );
    
        web.MasterUrl = masterPageUrl;
        web.CustomMasterUrl = masterPageUrl;
        web.Update();
    
        ctx.Load( web );
        ctx.ExecuteQuery();
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, October 14, 2016 8:03 AM
    Moderator
  • Hi Dennis,

    Thanks for your input. I already did this before posting to the forum, but masterpage is not getting updated.

    In your given code, you need to add ctx.Load(web); and ctx.ExecuteQuery(); before ctx.Web.ServerRelativeUrl line. Otherwise it would throw an error "The property or field 'ServerRelativeUrl' has not been initialized".

    Anyway let me know if there is any other option.

    var login = "dennis@xxx.onmicrosoft.com";
    var password = "xxxxxx";
    var securePassword = new SecureString();
    foreach (char c in password)
    {
        securePassword.AppendChar(c);
    }
    SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, securePassword);	 
    using (var ctx = new ClientContext("siteurl"))
    {	
        ctx.Credentials = onlineCredentials;
        var web = ctx.Web;
      ctx.Load( web );
        ctx.ExecuteQuery();
    
        var masterPageUrl = String.Format( "{0}/_catalogs/masterpage/seattle.master", ctx.Web.ServerRelativeUrl );
    
        web.MasterUrl = masterPageUrl;
        web.CustomMasterUrl = masterPageUrl;
        web.Update();
    
        ctx.Load( web );
        ctx.ExecuteQuery();
    }

    Regards,

    Sri

    Friday, October 14, 2016 8:52 AM