How to: Migrate a Web Site From One Location to Another
Applies to: SharePoint Foundation 2010
The following procedures provide an example of how to use the Content Migration object model to move a SharePoint Foundation Web site from one location to another.
To export the Web site
Add the following using directives to your project.
using System; using System.Collections.Generic; using System.Windows.Forms; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint.Deployment;
Imports System Imports System.Collections.Generic Imports System.Windows.Forms Imports Microsoft.SharePoint Imports Microsoft.SharePoint.Administration Imports Microsoft.SharePoint.Deployment
Create an SPExportSettings object to specify settings for the export operation.
SPExportSettings exportSettings = new SPExportSettings();
Dim exportSettings As New SPExportSettings()
Indicate the source URL.
exportSettings.SiteUrl = "http://webname";
exportSettings.SiteUrl = "http:// webname"
Indicate the type of export you want to do, for example, you can export all of a Web site's contents, or only incremental changes. In this example, we are exporting all of the data.
exportSettings.ExportMethod = SPExportMethodType.ExportAll;
exportSettings.ExportMethod = SPExportMethodType.ExportAll
Identify a location for the output file (the *.cmp file, which is also called a Content Migration package). The following statements create a file at c:\exportfile.cmp.
exportSettings.BaseFileName = "exportfile"; exportSettings.FileLocation = @"c:\";
exportSettings.BaseFileName = "exportfile" exportSettings.FileLocation = "c:\"
Determine which metadata you want to include when exporting the data. For example, do you want to include versioning information? Security information?
For this example, we are using all the default values—only the last major version of each item is migrated. No user or group information is migrated.
SPExport export = new SPExport(exportSettings); Export.Run();
Dim export As New SPExport(exportSettings) Export.Run()
To import the Web site
Create an instance of the SPImportSettings class to specify settings for the import operation.
SPImportSettings importSettings = new SPImportSettings;
Dim importSettings As SPImportSettings = New SPImportSettings
Specify the location of the Content Migration package that was created in step 3 of the export.
importSettings.BaseFileName = "exportfile"; importSettings.FileLocation = @"c:\";
importSettings.BaseFileName = "exportfile" importSettings.FileLocation = "c:\"
Specify the destination location where you want to create the Web site.
importSettings.SiteUrl = "http://newweb";
importSettings.SiteUrl = "http:// newweb"
Determine the metadata that you want to include when importing the data, for example, how to handle versioning, author/editor information for the files, and whether to retain GUIDs.
We again use the default values—new versions are appended, and no author/editor information or GUIDs are imported.
SPImport import = new SPImport(importSettings); Import.Run();
Dim import As New SPImport(importSettings) Import.Run()