How to find out what type of site a site is…

I’ve built a feature to active branding on a site including master page, navigation and themes, which I’ve been talking about a bit over the last few weeks. One issue, though is that meeting workspaces have a different master page to ‘normal’ master pages, so I need to set them to use a different ‘custom’ master page when the feature is activated. This means that my feature receiver has to ‘know’ if the site it’s being activated on is a Meeting Workspace, or some other site.

What defines the ‘type’ of a site is the template that was used in it’s creation. These are defined in 12TEMPLATE1033XML, with the actual configuration details being within the folders of 12TEMPLATESiteTemplates (the folder names match the names of the templates as defined in the XML).

Anyway, each site (SPWeb object in the object model) has a WebTemplate property, which is the name of the template used. Note that a template may have multiple configurations – for example, the Meeting Workspaces are several configurations of one ‘Template’. To see a list of the templates installed, I wrote a little console app containing the code:

SPSite siteCollection = new SPSite(@"http://vm-moss2007");
SPWebTemplateCollection templates = siteCollection.GetWebTemplates(1033);

foreach (SPWebTemplate t in templates)
Console.WriteLine("{0} - {1} - {2} - {3}", t.Lcid, t.Name, t.Title, t.Description );

…but the lazy may want to just check this list.

The upshot of it was that meeting workspace sites are just sites where the template begins with MPS :

SPSite siteCollection = new SPSite(@"http://vm-moss2007");
SPWeb site = siteCollection.OpenWeb( siteurl );
string isMeeting = (site.WebTemplate.StartsWith("MPS",StringComparison.OrdinalIgnoreCase))? "is":"is not";
Console.WriteLine("{0} ({1} - {2}) {3} a meeting workspace", site.Name, site.WebTemplateId ,site.WebTemplate,isMeeting );

Of course, this doesn’t solve everything. You could have a custom site template that begins with ‘MPS’ (though unlikely), or a custom site template that defines it’s own custom master page, like the Meeting Workspaces to (which is a bit more likely). If that happens, I guess I’ll just amend my code to compensate for that customer.

How to find out what type of site a site is…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.