SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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;

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

3) Or create a custom site definition with your feature

share|improve this answer
Thanks djeeg.. that worked like a charm!. thanks a lot. – C. Hoffmann Jan 27 '11 at 12:17
How do you set it in a custom site definition? Would it be in the Onet.xml - under <Configuration> element. I see there is a MasterUrl attribute, but removing that attrib doesn't inherit the parent's masterpage. – Dan Tshin May 17 '12 at 23:34

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.

share|improve this answer
James are you sure you can set the default master page in SP Designer.If yes can you please elaborate? Thanks – naijacoder Dec 1 '11 at 5:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.