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

if (includeSubSites)
foreach (SPWeb child in web.Webs)
SetCustomMasterPage(masterPage, child, true);


Got something to add?

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s