Share via


How to: Migrate a Web site from one location to another

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The following procedures provide an example of how to use the Content Migration object model to move a Windows SharePoint Services 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;
    
  2. Create an SPExportSettings object to specify settings for the export operation.

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

    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;
    
  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:\";
    
  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();
    

To import the Web site

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

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

    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();
    

See Also

Concepts

Using the Content Migration Object Model