SharePoint content migration using the content migration object model

September 12, 2009

Following on from a previous post, this post will focus on the SharePoint content migration object model.

For content migration scenarios that require you to export only selected content, or that require you to automate or customize migration operations, there is only one approach: you must write a custom solution that uses the APIs in the Microsoft.SharePoint.Deployment namespace.

It is important that before you choose to use selective migration that you have performed a full content migration first, so that the destination is a mirror image of the source.

Selective migration applies, typically, to content that needs to be migrated from server to server based on factors such as content version (current versus future), time stamp, and content state (approved versus in review, for example). Selection criteria provides a high degree of granularity from the scope of the site collection down; that is, you have selection control at the scope of the Web, the list, folder, and list item.

You can have any number of content management packages (.cmp) files in a migration operation, and you can also have multiple destinations. However, the objects contained in a given .cmp file must originate from a single site collection.

Had enough of the pre-amble? Lets move on to how you can start using the SharePoint contnect migration object model.

  1. Reference Microsoft.SharePoint.dll
    This can normally be located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI\Microsoft.SharePoint.dll
  2. Include the following Microsoft.Sharepoint.dll namespaces
    Add these using statements to the top of your class:

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Deployment;
  3. To export data to a content management package, adapt the following code to your requirements
    static void Export()
    // Full content migration
    string siteURL = “<Your SharePoint site URL>”
    string baseFileName = “<Your content package name>.cmp”;
    string dataFileLocation = @”c:\”;
    string logFileLocation = @”c:\<Your export log file name>.log”;

    SPExportSettings exportSettings = new SPExportSettings();
    exportSettings.SiteUrl = siteURL;
    exportSettings.ExportMethod = SPExportMethodType.ExportAll;
    exportSettings.BaseFileName = baseFileName;
    exportSettings.FileLocation = dataFileLocation;
    exportSettings.LogFilePath = logFileLocation;
    exportSettings.OverwriteExistingDataFile = true;
    exportSettings.CommandLineVerbose = true;
    SPExport export = new SPExport(exportSettings);

  4. Export selective content

    To export selective content add as many SPExportObjects to the SPExportSettings’ collection.

    As SharePoint objects are identified by GUID on the source server. You will need to find out the GUID of the object you wish to export first.

    Using a SPList as an example:

    string siteURL = “<Your SharePoint site URL>”
    SPSite systalkSite = new SPSite(siteURL);
    SPList mySelectiveContent= systalkSite.AllWebs[0].Lists[<Your selected list name>];

    SPExportObject exportObject = new SPExportObject();
    exportObject.Id = mySelectiveContent.ID;
    exportObject.Type = SPDeploymentObjectType.List;


  5. To import data from a content management package, adapt the following code to your requirements

    static void Import()
    // Package import
    System.Uri siteURL = new Uri(“”<Your SharePoint site URL>””);
    string baseDataFileName = “<Your content package name>.cmp”;
    string dataFileLocation = @”c:\”;
    string logFileLocation = @”c:\<Your export log file name>.log”;

    SPImportSettings importSettings = new SPImportSettings(siteURL, dataFileLocation, baseDataFileName);
    importSettings.RetainObjectIdentity = true;
    importSettings.CommandLineVerbose = true;
    importSettings.LogFilePath = logFileLocation;
    SPImport import = new SPImport(importSettings);


Theres a lot of scope for customisation using this approach, but these examples should be enough to get you started.

Further reading:
Key Concepts in Selective Migration

Selective Content Migration in Windows SharePoint Services 3.0


SharePoint content migration using Stsadm.exe

September 12, 2009

Following on from a previous post, this post will focus on the Windows SharePoint Services administrative application or stsadm.exe.

Stsadm.exe provides an easy way to migrate the contents of one Windows SharePoint Services site collection to another by using basic export and import operations. However, although this method is easy and simple to execute, there are are certain limitations:

  • Stsadm supports moving only entire Web sites ( SPWeb instances). You are not able to export selected items or lists.
  • You cannot retain object globally unique identifiers (GUIDs) when you migrate site objects. New identifiers are added at the migration target.
  • You can experience problems if you rerun Stsadm on site content that has already been imported. If that occurs, all list items that are not document libraries are duplicated on the target site.
  • You are limited in what parameters you can use as part of your import/export process, and as such have less control of these operations when compared to the SharePoint migration object mode (Microsoft.SharePoint.Deployment).

For more information on how to use this application see MSDN.

SharePoint migration planning

September 12, 2009

It is important to plan you SharePoint migration in advance, as the decisions made of what to include will determine which aspect of the SharePoint Migrations APIs which you will use.

As mentioned in previous posts you are restricted for choice of which API to use if you:

  1. Wish to retain your original object ids (GUIDs).
  2. Wish to only export selective content.

If either of these scenarios apply to you, then continue reading.

Use this flowchart to help you make the correct choices when planning your selective content migration:


SharePoint Administrative Toolkit v4.0 Announced

September 12, 2009

The fourth version of the SharePoint Administrative Toolkit for Administrators has just been announced. This is the final planned version for SharePoint 2007 and Windows SharePoint Services V3.0.

This release sees many more new and improved features including:

  • SharePoint Diagnostics Tool (SPDiag) update
  • Permissions Reporting Tool
  • Quota Management
  • Security Configuration Wizard Manifests

Follow the link to read more.