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);
    export.Run();
    }

  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;

    exportSettings.ExportObjects.Add(exportObject);

  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);
    import.Run();

    }

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

Advertisements

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-migration.planning


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.


SharePoint Content Migration

September 11, 2009

I was quite surprised when researching this topic that there is not a straight forward method of migrating information through Windows SharePoint Services administrative interface. I thought I would summarise my findings in a series of posts.

The content migration APIs provide a simple but flexible solution for migrating content between Windows SharePoint Services 3.0 web sites & web site collections. You can export the content related to a Windows SharePoint Services Web site, along with any dependencies (for example, security, roles, versioning, and other metadata), into single or multiple XML-formatted files called content migration packages. On import to the destination Web site, the packaged data is extracted and interpreted. You can also save the packages to a file server before migrating to a different server.

These APIs are not a replacement for a backup and restoration purposes.

There are three main ways to use the content migration APIs:

  1. Stsadm.exe
    Using Stsadm.exe, you can use the import and export operations to migrate data. However, you are limited in scope to a Web site only. In addition, you do not have the option of retaining GUIDs, which can be necessary in certain scenarios.
  2. SOAP
    You can use the ExportWeb and ImportWeb methods implemented in the Sites Web service to migrate data from a remote server. But, as is the case with Stsadm.exe, you are limited in scope to a Web site only. You also do not have the ability to retain GUIDs, which can be a requirement in certain scenarios.
  3. Content migration object model
    The object model provides the most control over your data migration scenarios. Using the object model, you can migrate anything, from a Web site to an item in a list, or a single document in a library. You can choose whether to include information about security, versioning, user roles, and other metadata appropriate to the objects you are migrating. The content migration object model is implemented in the Microsoft.SharePoint.Deployment namespace.

Drop in later to read my following posts as I dive into each of these methods of using the content migration APIs.


Stsadm.exe – access denied

September 10, 2009

When trying to use The Windows SharePoint Services administrative application Stsadm.exe to perform some tasks on a local WSS instance I received the following error:

stsadm-dos

I was trying to use this application using the same system account as used in the application pool configured for my SharePoint site (as suggested in this post.)

Drilling down into this problem in the System Event logs revealed the source of this problem: permission errors when attempting to execute a com server application (A related error & solution has been posted on the Microsoft support site here. This surfaced in the system event log as a series of DCOM errors every time I tried to execute the stsadm.exe tool.

stsadm-eventvwr

Opening one of these errors explained the problem.

stsadm-eventprops

Following this problem into the registry HKEY_CLASSES_ROOT\CLSID\CLSID value (where the CLSID value is the CLSID reported in the error details above) let me to the application that was failing when attempting to launch remotely: the IIS Admin Service.

The solution for this was to:

  • add the account to the local administrators group
  • grant the account sufficient permissions to launch the program using Component Services > DCOM Config > IIS Admin Service > Launch & Activation Permissions. Component services can be launched by typing dcomcnfg into the run dialog.

Web enabled InfoPath 2007 forms

January 22, 2009

InfoPath Forms Services is a server technology that allows users to fill out Microsoft Office InfoPath forms by using a Web browser. Users don’t need InfoPath installed on their computers to fill out an InfoPath form, nor are they required to download anything extra from the Web. All users need is access to a browser, such as Microsoft Internet Explorer, Apple Safari, or Firefox.

There is a a pre-requisite however that all web-enabled InfoPath form be deployed and accessed from a Form Services enabled server (either Microsoft Office Forms Server 2007 or Microsoft Office SharePoint Server 2007.)

Is there any way around this pre-requisite?

More info: