Share via


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

  1. 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
    
  2. Create an SPExportSettings object to specify settings for the export operation.

    SPExportSettings exportSettings = new SPExportSettings();
    
    Dim exportSettings As New SPExportSettings()
    
  3. Indicate the source URL.

    exportSettings.SiteUrl = "http://webname";
    
    exportSettings.SiteUrl = "http:// webname"
    
  4. 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
    
  5. 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:\"
    
  6. 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.

  7. Create a new instance of the SPExport class, pass it the SPExportSettings object, and run it.

    SPExport export = new SPExport(exportSettings);
    Export.Run();
    
    Dim export As New SPExport(exportSettings)
    Export.Run()
    

To import the Web site

  1. Create an instance of the SPImportSettings class to specify settings for the import operation.

    SPImportSettings importSettings = new SPImportSettings;
    
    Dim importSettings As SPImportSettings = New SPImportSettings
    
  2. 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:\"
    
  3. Specify the destination location where you want to create the Web site.

    importSettings.SiteUrl = "http://newweb";
    
    importSettings.SiteUrl = "http:// newweb"
    
  4. 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.

  5. Create a new instance of the SPImport class, pass it the SPImportSettings object, and run it.

    SPImport import = new SPImport(importSettings);
    Import.Run();
    
    Dim import As New SPImport(importSettings)
    Import.Run()
    

See Also

Concepts

Using the Content Migration Object Model