Using the Content Migration Object Model
Applies to: SharePoint Foundation 2010
Typically, the scenarios for content migration fall into the following categories:
Moving the contents of a site collection from one location to another.
Migrating only selected content files from one site to another based on specified criteria.
Exporting content for the purpose of having some process performed on it, and then re-importing it.
Synchronizing servers.
Regardless of the scenario, however, the basic steps are the same. Following are high-level steps performed in a typical migration operation, including some links to the related object model members for more information.
The first step is to decide on the content you plan to export. You use the SPExportSettings class to define these values for your export operation.
Determine which objects to migrate.
Using the content migration object model, you can export a site collection, a list, library, folder, file, or list item.
For more information, see the SPExportObjectCollection class.
Decide how much of an object's data you want to export. You can export all of an object's data and its dependencies, or you can choose to export only incremental changes.
To export incremental changes, you must decide whether to export data based on one of the following:
A particular date.
Changes made to a file since that last export (using the SharePoint Foundation change log).
For more information, see the ExportMethod property.
Identify a location for the output file (the *.cmp file, which is also called a content migration package).
For more information, see the BaseFileName and FileLocation properties.
Determine what metadata you want to include when exporting the data. For example, what type of versioning information do you want to export (the default is the last major version)? Do you want to export user and group information (by default, no user or group information is included)?
For more information, see the IncludeVersions and IncludeSecurity properties.
If you want, place limits on the size of your content migration package (.cmp) files. If the content files in a migration operation exceeds the specified file size limit, the operation automatically creates additional .cmp files, as needed.
For more information, see the FileMaxSize property.
Indicate how to handle warnings and errors during the export operation (by default, the export operation does not stop when it encounters a warning or nonfatal error).
For more information, see the HaltOnNonfatalError and HaltOnWarning properties.
After making these decisions and setting the values in the SPExportSettings class, pass it as a parameter to SPExport, and then run the export job.
After the export is complete, a content migration package is created at the location you defined in SPExportSettings. This file consists of a set of files that contain the content included in the export operation and metadata that describes the structure of the content.
Just as you defined settings for export in the SPExportSettings object, you now define values for import in the SPImportSettings object.
Determine what metadata to include when importing the data. For example:
How do you want the versioning information to appear (by default, versions are appended to files at the destination location)?
For more information, see the UpdateVersions property.
Do you want the objects to keep their original GUID? (By default, object identity is not retained.)
For more information, see the RetainObjectIdentity property.
Important
Use this property with caution—databases do not permit duplicate GUIDs. This property is most commonly used when you have two Web sites that are mirror images of each other, or in a publishing scenario, to indicate whether a file on one computer is the same as the file on another computer.
This functionality is available in the object model only. You cannot retain GUIDs using Stsadm.exe or the [Sites Web service]Web service.
Indicate how to handle warnings and errors during the import operation (by default, the import operation does not stop when it encounters a warning or nonfatal error).
For more information, see the HaltOnNonfatalError and HaltOnWarning properties.
After making these decisions and setting the values in the SPImportSettings class, pass it as a parameter to SPImport and run the import job.
See Also
Tasks
How to: Migrate a Web Site From One Location to Another
Concepts
Migrating Security Information