Your master page automatically on newly created (sub)sites

October 21st, 2011 | Posted by Jeffrey Paarhuis in Developing | Good to know

In my previous post on how to design and deploy a custom SharePoint master page I explained how to create an own branded master page and how to deploy that master page to your SharePoint site. Now I first stumbled upon the problem that the master page doesn’t get automatically applied to newly created (sub)sites, and secondly I received a comment from a reader describing the exact same problem. So I decided to write my findings and solution to the open world. Here it is.

The problem is very simple: You create your own master page, you apply your master page to all sites and it does that, nice, but when you create a new site you just get the old v4.master on that site and not your custom master page. Everyone with this problem, if you followed my previous post or not, can follow this solution. It doesn’t even matter what SharePoint version you’re using.

When I Googled for a bit, I found out that there is no out-of-the-box-solution for this and a lot of guys use Visual Studio to solve this. You could program an event receiver that sets your master page to every new site. Or you could program a Feature that holds your master page and apply that feature to a site definition. But I find that a bit heavy and not very flexible solution. So I played around a bit and found a solution myself without the use of Visual Studio or programming at all.

Here we go:

You should have your master page deployed to the main sites master pages gallery. You should see your masterpage when going to http:///_catalogs/masterpage/Forms/AllItems.aspx

(Yes I’m using Chrome)

Now create a new blank Team Site using whatever name you like (you won’t see it in the end).

Now go to Site Settings and click “Save site as template” under Site Actions and go save the site as a template.

On the next screen click on the link to go to the solution gallery. In the solution gallery just click on the name of your just created template to download it. Save it somewhere where you can easily find it.

Did you know that as WSP is in fact just a CAB file? That’s why we need a tool that can extract and recreate our wsp. I used the tool ACDZip, which has a free x-days trial. You can get it here http://acdzip.findmysoft.com/. A reader has also mentioned the tool IZArc, which is free. A great alternative.

Now find your file and rename it from TemplateWithoutMyMasterPage.wsp to TemplateWithoutMyMasterPage.cab, you should see your icon change.

Open the file with ACDZip and extract the ONet.xml file from theWebTemplateONet.xml to a location where you can edit it easily.

 

Now edit the following line of code

masterpage/v4.master" ThemedCssFolderUrl="">

to

<Configuration ID="0" Name="Default" MasterUrl="/_catalogs/masterpage/mymaster.master" ThemedCssFolderUrl="">

Don’t forget the slash before _catalogs. This will ensure that the mymaster.master from the master page gallery on the root of the site gets used.

Save the file and put it back in the archive (drag and drop), it will automatically rebuild the archive. Rename the file back to a wsp file, I also used another file name.

Upload the file into the Solution Gallery by using the Upload Solution button on the ribbon of Solutions.

 

In the next screen you must upgrade the solution.

You can now use the new template to create a site with your masterpage. Go ahead and try. Site Actions, New Site, scroll down and select the template, fill in a title and url and create the site.

You should now have your master page automatically applied.

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

31 Responses



Leave a Reply to KK Cancel reply

%d bloggers like this: