What’s the best way to add a custom masterpage to a subsite that is being created programmatically in a feature event receiver? Each of these 50 subsites gets its own “_catalogs/masterpage”, so I have a feeling that Elements.xml for the root-site’s Module/Elements.xml is out. More feature receiver code? PowerShell post-deployment processing?
A:
You have following choices to set master page for the site: 1) Using Sharepoint Browser UI (from Site Settings page) 2) Using Custom site definitions 3) Programmatically 4) Using SharePoint Designer
Looking at your scenario, no 3 is an option. You may want to do it in the Feature Receiver itself.
Ashish Patel
2010-10-15 20:14:19
+1
A:
Is this going to be 50 copies of the same Master Page?
If not, I can't really picture how the Master Page will be specially made using code, but also a Feature Module element is certainly out.
But if it is 50 copies of the same file, you could deploy the Master Page to the Gallery one time using a Feature Module element. Then in your Feature Receiver, make a copy of that file with a new name in the Master Page Gallery and attach it to your website:
web.MasterUrl = "_catalogs/masterpage/custom_v4.master";
web.CustomMasterUrl = "_catalogs/masterpage/custom_v4.master";
web.Update();
Rich Bennema
2010-10-15 20:52:43