1 out of 1 rated this helpful - Rate this topic

SPWeb.CustomMasterUrl Property

Gets or sets the URL for a custom master page file to apply to the website.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
public string CustomMasterUrl { get; set; }

Property Value

Type: System.String
A string that contains the URL of the custom master page.

At runtime, the value in this property replaces the ~masterurl/custom.master token in content pages.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Using SPWeb.CustomMasterUrl And The Web Property Bag
When using the SPWeb.CustomMasterUrl property it is advisable to store the old master page pointers within the SPWeb property bag. An example of this in a SharePoint feature receiver is provided below:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
if (site != null)
{
SPWeb rootWeb = site.RootWeb;
rootWeb.AllProperties["OldMasterUrl"] = rootWeb.MasterUrl;
rootWeb.AllProperties["OldCustomMasterUrl"] = rootWeb.CustomMasterUrl;
rootWeb.MasterUrl = "string to master page";
rootWeb.CustomMasterUrl = "string to master page";
rootWeb.Update();
}
else
{
return;
}
}

Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com