SPWeb.CustomMasterUrl Property
Gets or sets the URL for a custom master page file to apply to the website.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
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
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
- 10/15/2010
- Adam Buenz - MVP