Content Import/Export

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 Microsoft.SharePoint.Deployment APIs in Windows SharePoint Services 3.0 provide a flexible set of tools for migrating content between Windows SharePoint Services Web sites. Windows SharePoint Services uses the concept of the content migration package, which can include either single or multiple XML files, and then provides a flexible set of APIs to enable exporting and importing the migration packages. The content import/export feature of the deployment object model allows you to export not only Web site content but also existing dependencies, like security features, user roles, versioning data, workflows, and other metadata.

The Microsoft.SharePoint.Deployment object model is designed to work with data ranging from an entire Web site to a single item in a list or library. You can select the level of metadata to include with migrated content, as well as choose whether to do a full migration or provide only an incremental update.

Content Migration Using the Deployment Object Model

The import/export features of the Microsoft.SharePoint.Deployment object model uses two key objects: Microsoft.SharePoint.Deployment.SPImport and Microsoft.SharePoint.Deployment.SPExport. However, before you run the import or export operations using these objects, you must first specify your import or export settings using Microsoft.SharePoint.Deployment.SPImportSettings and Microsoft.SharePoint.Deployment.SPExportSettings objects. Then you simply call the Run() method on the SPImport or SPExport object, as appropriate.


The following code illustrates how to use the deployment object model to export a SharePoint site from a source location and import it to a destination location.

private void ExportImport(string sourceUrl, string destinationUrl)
    string fileName = Export(sourceUrl);
    Log.Comment("Local filename for this export/import is {0}",             fileName);
    Import(destinationUrl, fileName);

private string Export(string siteURL)
    Microsoft.SharePoint.Deployment.SPExportSettings exportSettings =
        new Microsoft.SharePoint.Deployment.SPExportSettings();
    exportSettings.AutoGenerateDataFileName = true;
    exportSettings.ExportMethod =
    exportSettings.SiteUrl = siteURL;
    exportSettings.IncludeSecurity =
    exportSettings.IncludeVersions =
    Microsoft.SharePoint.Deployment.SPExport export =
        new Microsoft.SharePoint.Deployment.SPExport(exportSettings);
    Log.Comment("Starting export of URL {0}", siteURL);
    return exportSettings.FileLocation + "\\" +         exportSettings.BaseFileName;
private void Import(string siteURL, string fileToImport)
    Microsoft.SharePoint.Deployment.SPImportSettings importSettings =
        new Microsoft.SharePoint.Deployment.SPImportSettings();
    importSettings.BaseFileName =         System.IO.Path.GetFileName(fileToImport);
importSettings.FileLocation =         System.IO.Path.GetDirectoryName(fileToImport);
    importSettings.SiteUrl = siteURL;
    importSettings.RetainObjectIdentity = false;
    importSettings.IncludeSecurity =
    importSettings.UpdateVersions =
    importSettings.UserInfoDateTime =
        Microsoft.SharePoint.Deployment.SPImportUserInfoDateTimeOption.             ImportAll;
    Microsoft.SharePoint.Deployment.SPImport import =
        new Microsoft.SharePoint.Deployment.SPImport(importSettings);
    Log.Comment("Starting import to URL {0}", siteURL);

Content Migration Using the Command-Line Tool STSADM

The command-line tool STSADM.exe supports only basic import and export operations and is only useful when importing or exporting entire SharePoint Web sites or when reparenting a Web site. Content migrated using this tool will not retain object GUIDs. Note that you cannot use this utility to import or export individual items or lists.


The following example illustrates how to export the contents of a Web site using the command-line tool STSADM.exe.

stsadm.exe -o export
    -url <URL to be exported>
    -filename <export file name>
    [-versions <1-4>
        1 - Last major version for files and list items (default)
        2 - The current version, either the last major or the last minor
        3 - Last major and last minor version for files and list items
        4 - All versions for files and list items]
    [-cabsize <integer from 1-1024 megabytes>]


You must use the -includeusersecurity parameter in order to preserve time stamps, security information, and user data.


The following example illustrates how to import the contents of a Web site using the command-line tool STSADM.exe.

stsadm.exe -o import
    -url <URL to import to>
    -filename <import file name>
    [-updateversions <1-4>
        1 - Add new versions to the current file (default)
        2 - Overwrite the file and all its versions (delete then insert)
        3 - Ignore the file
        4 - Terminate with conflicts]


The following code provides a sample batch file for importing and exporting content, using the most common settings. You can copy and paste the following code into a .bat file.

@echo off

if not "%1"=="" goto ExportImport

echo **** Usage
echo This batch file will automatically export the default site collection to a newly created site collection
echo You need to specify the name of the newly created site collection as an argument
echo Example: PrimeIt.bat NewSite
echo The example will create http://localhost/sites/NewSite, and export http://localhost into it, preserving user security.

goto end

echo ************* Determine the Location to stsadm.exe
if EXIST "%CommonProgramFiles%\Microsoft Shared Debug\Web Server Extensions\12\bin\stsadm.exe" set BinDir=%CommonProgramFiles%\Microsoft Shared Debug\Web Server Extensions\12\bin
if EXIST "%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\bin\stsadm.exe" set BinDir=%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\bin
echo Determined that the location to stsadm is %BinDir%

@echo on
@echo ************* Backup the root site collection
"%BinDir%\stsadm.exe" -o export -url http://localhost -filename %TEMP%\ -includeusersecurity -versions 4 -overwrite

@echo ************* Create a destination site
"%BinDir%\stsadm.exe" -o createsite -url http://localhost/sites/%1 -ownerlogin %UserDomain%\%UserName% -owneremail -sitetemplate STS

@echo ************* Import into the new site
"%BinDir%\stsadm.exe" -o import -url http://localhost/sites/%1 -filename %TEMP%\ -includeusersecurity

@echo off

See Also




Content Migration Overview