I’ve come across a couple of occasions where I needed to copy the structure and layout of one Sitefinity site into an existing Sitefinity database. For example when moving from a development or staging environment to production.
I did some research and found no point-and-click solution for this so far. The Sitefinity API does support duplicating pages but that does not seem to work well for moving pages from one database to another.
Then I came across the handy site export feature in Sitefinity. This allows you to export an entire site into a zip. The zip can be used to create a new site. Under the hood there’s and ExportModule that’s doing all the work. The zip contains both the site’s files and a set of XML files that hold the site structure and any content you may have entered. So, to duplicate a site into an existing database here’s what to do:
1. Export the site and collect the zip file
The zip will be in the App_Data\Sitefinity_Exports folder of the exported site.
2. Extract the XML data files
Go into the zip. There’s a second zip inside called project.zip. Extract that zip and copy the App_Data/Sitefinity_DataImport folder inside it into your existing site.
3. Configure the CMS provider to use a new application
Go into your web.config and search for the cms section and add (or modify) the applicationName attribute.
<cms defaultProvider="Sitefinity" pageExtension=".aspx" projectName="MyProject" disabled="false" pageEditorUIMode="Overlay"> <providers> <clear/> <add connectionStringName="DefaultConnection" allowPageHistory="true" allowPageWorkflow="false" cachingProviderName="ASPNET" name="Sitefinity" type="Telerik.Cms.Data.DefaultProvider, Telerik.Cms.Data" applicationName="/newsite" /> ... </providers> ... </cms>
4. Import the XML data
Copy the attached Import.aspx into the root of your site and navigate to it. It will allow you to select a data set to import. The code that does the real work:
var tool = new SiteExporter(); tool.Import( "Your-data-set" );
As always, you should be cautious so MAKE A BACKUP OF THE TARGET DATABASE BEFORE IMPORTING!
5. Login and set the home page
Right now there is no home page for the new site yet. Login an set the home page to activate the new layout.
Don’t forget to remove the Import.aspx file from your site.
Note that you can switch back to the old layout at any time by reverting the applicationName setting in web.config.
Source code: SitefinityImport.zip