using (SPSite site = new SPSite("http://siteUrl")) { using (SPWeb web = site.OpenWeb()) { string newMasterPage = "newMasterPage.master"; string webAppRelativePath = site.ServerRelativeUrl.TrimEnd(new char[] { '/' }); //Site master page web.CustomMasterUrl = string.Format("{0}/_catalogs/masterpage/{1}", webAppRelativePath, newMasterPage); //System master page web.MasterUrl = string.Format("{0}/_catalogs/masterpage/{1}", webAppRelativePath, newMasterPage); web.Update(); } }
Here we apply the new MasterPage to both site pages and system pages.
No comments:
Post a Comment