SharePoint set custom masterpage on site

Here is a function that will set a site (including sub sites) to use a custom masterpage.

You pass in the masterpage, web, and if you want to include sub sites (it will call itself with the sub site name).

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();
}
}
}

 

Advertisements

Got something to add?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s