0

I created a site template from a one page site that uses a custom master page for the front end, the default master for the back end. When a new site is created from the template, the front end page reverts to the default master page and I have to manually correct it in SP Designer. Is there a way to switch the template for (any) site pages to the custom master without any manual interaction? This is the part that needs to change:

<%@ Page language="C#" MasterPageFile="~masterurl/custom.master"      Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" meta:webpartpageexpansion="full"  %>
  • Under the site collection settings, have you checked the option for all sites/subsites to directly inherit masterpage from the parent? This will automatically apply the selected masterpage on site creation. – Ransher Singh Dec 26 '14 at 16:02
  • Not an option in Foundation. – matt Jan 20 '15 at 3:16
  • not sure if this works on 2010 but worth a check: sharepointnutsandbolts.com/2014/09/… – Manu Jan 21 '15 at 15:41
1

Foundation does not have the option as the "Sharepoint Server Publishing feature" is needed for allowing inheriting of masterpage by child sites from the parent site.

However you can use powershell to achieve the same effect

$site = Get-SPSite http://sharepoint 

$site | Get-SPWeb -limit all | % {
$_.CustomMasterUrl = "/_catalogs/masterpage/CUSTOM.master" 

$_.MasterUrl = "/_catalogs/masterpage/CUSTOM.master"  
$_.Update()   
}
  • I've a feeling that will change every page when I want to target the "front end " pages only, not the admin pages. I can do that in SPD before saving the template by making the custom master the default, but it gets applied to all pages. It's easy enough to select the custom master in SPD but the client is resisting....... – matt Jan 22 '15 at 0:16
0

Follow these steps-

  1. Create custom master page and add it in features.
  2. Add an Event receiver on it.
  3. Write code as given below for FeatureActivated and FeatureDeactivating.

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {

SPSite site = properties.Feature.Parent as SPSite; if (site != null) { SPWeb rootWeb = site.RootWeb; string masterurl = rootWeb.ServerRelativeUrl; if (!masterurl.EndsWith("/")) { masterurl += "/"; } masterurl += "_catalogs/masterpage/PaperlessOffice.master"; // iterate through all the webs in the site collection foreach (SPWeb web in site.AllWebs) { web.Properties["OldMasterUrl"] = web.MasterUrl; //system master page for this site and all sites that inherit from it. web.MasterUrl = masterurl; //master page to be used by this site and all sites that inherit from it. web.CustomMasterUrl = masterurl; web.Update(); web.Dispose(); } } } public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; if (site != null) { // iterate through all the webs in the site collection foreach (SPWeb web in site.AllWebs) { if (!String.IsNullOrEmpty(web.Properties["OldMasterUrl"])) { //system master page for this site and all sites that inherit from it. web.MasterUrl = web.Properties["OldMasterUrl"]; //master page to be used by this site and all sites that inherit from it. web.CustomMasterUrl = web.Properties["OldMasterUrl"]; web.Update(); } web.Dispose(); } } }

Use ServerRelativeUrl not Absolute path.

  • Ronak, thanks for formatting that.I have tried doing that but failed. – Vikas Bansal Feb 10 '15 at 13:33

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.