Programmatically create a site collection with the 2010 Exerience

I was working on a project today and one of the requirements was, using a Timer Job, run an Export of an existing site collection and then Import it as a new site collection. The code to do this was relatively straight forward. But then when testing I found that the site collection being copied was (intentionally) still in SharePoint 2010 mode (experience).

The change was simple. There is an override when creating a new SPSite that lets you pass in the CompatibilityLevel. The value for the CompatibilityLevel parameter can be either 14 (for SharePoint 2010) or 15 (for SharePoint 2013). You must also pass in the WebTemplate, which for a Team Site, is STS#0.

Here is an example of what the code could look like:

using (SPSite osite = contentDB.Sites.Add({SiteURL}, {SiteName}, String.Empty, 1033, 14, "STS#0", {OwnerLogin}, {OwnerName}, {OwnerEmail}, {SecondaryContactLogin{, {SecondaryContactName}, {SecondaryContactEmail}))

	// Execute your code