If you worked with SharePoint 2010 master pages – you probably will know that now SharePoint allows you to set separate master page for system and the rest of the site. That’s great, but there are few tricks to it.
So the master page that will be used on site is just a regular master page that your users will see when they browse the site. The system master page is the one that you or potentially your users will see when they access properties of items, settings, and any other form related pages. You might have the same master page for both but in case you don’t here is how you can set them.
You can set your master page through the UI by navigating to here: http://[site]/_Layouts/ChangeSiteMasterPage.aspx
and changing the options as shown below:
If you’re doing site deployment, or decide to make the change programmatically- you will probably want to automate the process using a feature.
Below is the code of feature receiver added to a typical Web scoped feature:
public override void FeatureActivated(SPFeatureReceiverProperties
properties)
{
SPWeb currentWeb = properties.Feature.Parent as SPWeb;
PublishingWeb currentPublishingWeb = PublishingWeb.
GetPublishingWeb(currentWeb);
Guid siteID = currentWeb.Site.ID;
Guid webID = currentWeb.ID;
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb(webID))
{
PublishingWeb area = PublishingWeb.
GetPublishingWeb(web);
area.MasterUrl.SetValue(
area.MasterUrl.Value.Replace("my.Master", "v4.Master"));
area.MasterUrl.SetInherit(false, true);
area.Update();
}
}
});
}
Above, MasterUrldenotes the system master page and CustomMasterUrldenotes site URL. You can’t set the Value property directly. Be careful to the format in which your URL of the master page is provided. If you provide invalid URL you may receive an error message or your entry will be rejected without any notification and the only way to find out it was rejected is to check out the URL in the Value property.
Good Luck!
