Sharepoint: change current site collection’s master page
CodeKeep C# Feed Novembre 13th, 2008
Description: Change master page programmatically
Link: http://www.codekeep.net/snippets/6ad7047e-c32b-40bc-b6c6-48b154efec73.aspx
var newMaster = properties.Feature.Properties["MasterName"].Value;
if (!string.IsNullOrEmpty(newMaster))
{
using (var curSite = (SPSite)properties.Feature.Parent)
{
using (var curWeb = curSite.OpenWeb(""))
{
//got the current site and root web in site, now set the master Url
//to our master page that should have been uploaded as part
//of our feature
if (curWeb.MasterUrl.Contains("default.master"))
{
curWeb.MasterUrl = curWeb.MasterUrl.Replace("default.master", newMaster);
curWeb.Update();
UpdateLog("MasterUrl property updated for web " + curWeb.Title,
EventLogEntryType.Information);
}
}
}
}






