Wednesday, October 9, 2013

Creating a site collection in 2010 mode in SharePoint 2013

Today I got phoned up by a friend who asked how on earth he could programmatically create a site collection in 2010 mode in SharePoint 2013. Why he wanted to do this I’m not sure, and it’s not the point of this post :)

It’s actually quite easy if you look at the documentation of some of the SPSiteCollection.Add() methods which take an int as a compabilityLevel parameter. Passing in 14 in this parameter will ensure you get the 2010 look and feel. For reference the SPSite.SelfServiceCreateSite() method has similar overloads.

SPWebApplication webApp = new SPSite(http://host).WebApplication;
SPSiteCollection siteCollections = webApp.Sites;
uint lcid = 1033;
int compatLevel = 14;
string webTemplate = "STS#0";
SPSite newSiteCollection = siteCollections.Add("sites/test", "Title", "Description", 1033, compatLevel, webTemplate,
 "DOMAIN\\User", "Name", "Email_Address", "DOMAIN\\User", "Name", "Email_Address");

If you want to do it I PowerShell you can use the following command:

New-SPSite -Url http://host/sites/test -OwnerAlias "DOMAIN\User" -Template "STS#0" -CompatibilityLevel 14

And via Central Admin:

image