Question

I have a custom master page applied to my site collection. When i create a new sub site, it doesn't come with this custom master page applied to it. I can always go to /_layouts/changesitemasterpage.aspx on my root site and check the options "Reset all subsites to inherit this Site Master Page setting" and it will apply the same master to every single subsite.

I'm trying to make a feature that automatically does that when i create a new subsite. Is that possible to be done?

Was it helpful?

Solution

1) Create a feature, with event receiver

public class CustomFeatureReceiver : Microsoft.SharePoint.SPFeatureReceiver {
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
        using(SPSite site = new SPSite("")) {
            using(SPWeb web = site.OpenWeb("")) {
                string url += "_catalogs/masterpage/custom.main.master";
                web.CustomMasterUrl = url;
                web.MasterUrl = url;
                web.Update();
            }
        }
    }
}

2) Create another feature and staple your first feature to the site definition

http://msdn.microsoft.com/en-us/library/bb861862(office.12).aspx

3) Or create a custom site definition with your feature

OTHER TIPS

If you open the master page gallery in SharePoint Designer you should able to set the default master page in your site, which I think should set all newly created subsites to use that master page.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top