Programmatically Copy Content from Site collection to other SharePoint 2010 (content deployment)

The best approach to copy content between servers i.e. from the source site collection to the destination site collection in SharePoint 2010 is by using Content Deployment. If your new to content deployment please see Introduction to Content Deployment and Steps for Content Deployment.

In this post however, we will see how to use the Content deployment and copy the content from site collection from URL http://SourceServer/sites/SC1 to a destination site collection at URL http://DestiServer/sites/SC2. The example is a Console Application to Deploy Content Between two different SharePoint Servers.

shows how to deploy content between servers; a site collection from URL
http://serverA/sites/SC1 is deployed to a destination site collection at URL http://serverB/sites/SC2.
Listing 18–8. Console Application to Deploy Content Between Servers
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Publishing.Administration;
namespace DeployContent
public class Program
static void Main( string[] args )
Example example = new Example();
public class Example

public void Invoke()
// Path settings
string pathName = "My Deployment Path";
Uri sourceServerUri = new Uri( "http://SourceServer" );
string sourceSiteCollection = "/sites/SC1";
Uri destinationAdminUri = new Uri( "http://DestiServer:3000" );
Uri destinationServerUri = new Uri( "http://DestiServer" );
string destinationSiteCollection = "/sites/SC2";
// Job settings
string jobName = "My Content Deployment Job";
ContentDeploymentPath path = null;
ContentDeploymentJob job = null;

// Note: the DESTINATION farm must be configured to accept incoming deployment jobs.
ContentDeploymentConfiguration config = ContentDeploymentConfiguration.GetInstance();
config.AcceptIncomingJobs = true;
config.RequiresSecureConnection = false;

// Create a deployment path.
ContentDeploymentPathCollection allPaths = ContentDeploymentPath.GetAllPaths();
path = allPaths.Add();
path.Name = pathName;
path.SourceServerUri = sourceServerUri;
path.SourceSiteCollection = sourceSiteCollection;
path.DestinationAdminServerUri = destinationAdminUri;
path.DestinationServerUri = destinationServerUri;
path.DestinationSiteCollection = destinationSiteCollection;

// Create a job associated with the path
job = ContentDeploymentJob.GetAllJobs().Add();
job.JobType = ContentDeploymentJobType.ServerToServer;
job.Name = jobName;
job.Path = path;
catch ( Exception ex )
Console.Error.WriteLine( ex.StackTrace );
// Delete the job that was created.
if ( job != null ) job.Delete();
// Delete the path that was created.
if ( path != null ) path.Delete();



This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at .

Copyright (c) 2010 @ All rights are reserved.Do Not Copy.

@ Learning