As noted previously, Meeting Workspaces use a different master page to the ‘normal’ master pages in SharePoint. This is a little annoying – if I need to apply a new master page, how would I do this?
Well, you can activate a new master page in a Feature Receiver. And we can detect the type of site we’re dealing with. Why not combine the two techniques:
private const string MASTERPAGEFILE = "MasterPageFile";
private const string MEETINGMASTERPAGEFILE = "MeetingMasterPageFile";
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb site = properties.Feature.Parent as SPWeb;
SPFeatureProperty masterFile = properties.Definition.Properties[MASTERPAGEFILE];
SPFeatureProperty meetingMasterFile = properties.Definition.Properties[MEETINGMASTERPAGEFILE];
char[] slashes = { '/' };
//Is the site a Meeting Workspace?
if (site.WebTemplate.StartsWith("MPS"))
{
site.CustomMasterUrl = site.ServerRelativeUrl.TrimEnd(slashes) + "/_catalogs/masterpage/" + meetingMasterFile.Value;
site.MasterUrl = site.ServerRelativeUrl.TrimEnd(slashes) + "/_catalogs/masterpage/" + masterFile.Value;
}
else
{
site.CustomMasterUrl = site.ServerRelativeUrl.TrimEnd(slashes) + "/_catalogs/masterpage/" + masterFile.Value;
site.MasterUrl = site.ServerRelativeUrl.TrimEnd(slashes) + "/_catalogs/masterpage/" + masterFile.Value;
}
site.Update();
}
Interesting,
now it is easy to change master page programmaticly
Thanks for writing, most people don’t bother.
Thanks for sharing.
One note though, instead of testing template name like this
if (site.WebTemplate.StartsWith(“MPS”))
I would recommend using
if (SPMeeting.IsMeetingWorkspaceWeb(site))
Regards
Nice tip!