When using a custom master page with SharePoint you need to set all your sub sites to use the same master page.
Here is a function that will recursively change the master page for all sub sites.
Just call if from you feature receiver passing in the master page, the web you want to start with, and if you want to include sub sites.
/// <summary>
/// Sets the custom master page URL for the site.
/// </summary>
/// <param name="masterPage">Master page name.</param>
/// <param name="web">Site that you want to set the mater page.</param>
/// <param name="includeSubSites">Allows you to set all sub-sites as well.</param>
public static void SetCustomMasterPage(string masterPage, SPWeb web, bool includeSubSites)
{
web.CustomMasterUrl = GetMasterPageUrl(masterPage);
web.Update();
if (includeSubSites)
{
foreach (SPWeb child in web.Webs)
{
SetCustomMasterPage(masterPage, child, true);
child.Dispose();
}
}
}
You are right, but problem is that when we create a new site then this site does not inherties master page setting automatically. There are any way to do it? I have created a custom site difinition it is working fine but when client use OOTB Site template like Record Center or any others then problem is occurred.
Thanks for your valuable posting…
Regards,
Manas Mondal
Comment by Manas Mondal — May 6, 2010 @ 2:29 am