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.
Pingback: Designing and deploying a new master page for Sharepoint Foundation 2010 « Jeffrey Paarhuis: SharePoint Blog
This is a great solution; I’m really glad you shared. To re-cab though, I’ve been using IZArc because it’s free.
Ah, good one! I was looking for a good (read free) alternative. Thanks, I will mention it!
i am not able to rebuils wsp back
can you please give me steps to build wsp back
Nice post!
Note: You may need to alter the ID from the Configuration element.
Question about how you upload the modified file. The only way I could get the Upgrade Solution was to change the name of the modified file. If i over-write the exiting file with the modified template, provisioning the site based on the modified template fails. If you modify the name, then you have two templates in the solutions gallery. Am I missing something?
If you upload the file using the same name a screen will appear with the ability to upgrade the solution. There you upgrade the solution and the new template will be available.
This is a great solution. are there any drawbacks?
yes
Would you mind telling me the drawbacks before I use this solution?
Just joking.
The drawback would be that you have to do this trick for every update to the masterpage.
If you’re not familiar with Visual Studio and don’t want to bother a developer, this is the way to go. Otherwise I would recommend a feature receiver and feature stapling that enables the masterpage on each new site.
haha..ok Thank you very much. I think I’ll stick with this solution then..
What steps must change in order to utilize this in SP 2013? I’ve tried implementing these steps and all is good until I try to create new site using the new Masterpage. This functionality appears to be different in the newer version.
I haven’t done this yet in 2013. If you find out, please let us know!
Bah!
After finding the last step did not apply, I was able to successfully apply the theme, instead, by creating a new subsite and then in site settings, choose site features. Activate “SharePoint Server Publishing” and Voila! Thanks for your post.
Is something like this possible in SPO 2013?
I would recommend creating a branding package with feature stapling. That’s a more neat solution and compatible with Online
This is a great solution. many thanks
Hi, This is a great article.
I have question, Is article is applied only if we creating a sub site with the same Template. Right. But in my case i want to create a sub site with another template. For example i have a team site as top level site i want to apply my custom master page to Document Work space (Sub site created under team site). Is there any way to apply my custom master page with newly created sub site.? Here am created new sub site on run time (Created custom web part to create a sub site. user will give the url, that’sit sub site will be created with the user specified Url)
Thanks in advance.
You could change the masterpage in the web part code using the following code:
SPWeb web = newlycreatedweb;
web.CustomMasterUrl = “/masterpage/custom1.master”;
web.MasterUrl = “/masterpage/custom1.master”;
You can also take a look at feature stapling for masterpages, actually that’s the recommended way.
Hi,
This article explains how to apply the master page sitting in the root site to a sub site.
I have question. Will this work for the site collection created using the path other than (/), Ex: http://dev1/sites/sampleSiteCollection/.
Because, MasterUrl=”/_catalogs/masterpage/mymaster.master” works only if the root site is created using just the slash. If you want the same thing to work for other site collections created using a different path this fails.
I have the same issue as I need to create workspaces as separate site collections under /sites path and this fails as the masterpage cannot refer in onet.xml to different site collection. I tried tilde (~) and everything in the path and it just wont’ work.
Check this out http://blogs.msdn.com/b/bgeoffro/archive/2009/06/22/master-pages-revisited-references-to-master-pages-in-sharepoint.aspx
Hi Friends,
I am getting file not found error, after updating the Onet.xml.
Kindly help me regardind this issue
Unable to access web scoped feature (Id: 97f5709a-a956-451e-8b24-aaf65bd8badb) because it references a non-existent or broken web (Id: 1ea97286-da10-408f-b924-1cb07f0b4386) on site ‘http://xxxx/’. Exception: System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.SPWebCollection.get_Item(Guid id)
at Microsoft.SharePoint.SPFeatureEnumeratorBase.GetCachedWeb(SPSite site, Guid webId, Guid featureId)
If I were you I would redo the “save site as template” action and go from there.
Working great for Foundation!!! Thanks
i am not able to chnage cab file back to wsp,it s not getting converted.Please help
What tool are you using for it?
I followed these steps for SharePoint 2013 to update the custom master page URL and deployed, still facing “Sorry, something went wrong. File Not Found.” however master page is present in gallery.
Hey ,
Scenario :
I have a publishing Site as Parent Site. I am creating Team site as child site. What should be good way to implement parent master page to child site.And main constraint is i m using share point online. Child site might be used for re usability.
Unfotunately, I have redefined my masterpage as expected but the masterpage is not applied when I have tried to create a new site with the new template site 🙁
Is there anybody found a way to apply to aplly the master page as well?