如何:部署服务器之间的内容
此代码示例演示如何使用对象模型来创建在网站集合之间部署内容的路径和作业。此代码假定源网站集合和目标网站集合位于相同的服务器场中。但是,可以在不同的服务器场之间配置路径。此代码执行的任务也可以通过 SharePoint 中心管理中的用户界面来完成。
路径连接源网站集合和目标网站集合;作业控制复制哪些内容以及何时复制。Microsoft Office SharePoint Server 2007 仅支持源到目标的部署,不支持将多个源部署到一个目标或将内容从目标部署回源。部署在默认情况下是增量的且由中心管理员来配置。
下面的示例演示如何指定路径和作业设置、配置此场的内容部署和创建部署路径以及与其关联的作业。
示例
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Publishing.Administration;
namespace DeploymentAPISample
{
// In this sample, we assume the following:
// Content is being deployed from a source site collection to
// a destination site collection within the same farm.
// The SharePoint Central Admininstration Web application is
// accessible through port 8080.
// The source site collection is the root site collection on
// port 80.
// The destination site collection is on a managed path on
// port 81.
class Program
{
static void Main( string[] args )
{
DeploymentExample example = new DeploymentExample();
example.Invoke();
}
}
class DeploymentExample
{
public void Invoke()
{
// Path settings
string pathName = "My Deployment Path";
Uri sourceServerUri = new Uri( "https://server" );
string sourceSiteCollection = "/";
Uri destinationAdminUri = new Uri( "https://server:8080" );
Uri destinationServerUri = new Uri( "https://server:81" );
string destinationSiteCollection = "/sites/deploymentdestination";
// Job settings
string jobName = "My Deployment Job";
ContentDeploymentPath path = null;
ContentDeploymentJob job = null;
try
{
// Configure Content Deployment for this farm.
// Note: If you are deploying between farms,
// the DESTINATION farm must be configured
// to accept incoming deployment jobs.
ContentDeploymentConfiguration config = ContentDeploymentConfiguration.GetInstance();
config.AcceptIncomingJobs = true;
config.RequiresSecureConnection = false; // NOTE: This is the simplest configuration, but is not the recommended secure setting
config.Update();
// 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;
path.Update();
// Create a job associated with the path you created.
job = ContentDeploymentJob.GetAllJobs().Add();
job.JobType = ContentDeploymentJobType.ServerToServer;
job.Name = jobName;
job.Path = path;
job.Update();
job.Run();
}
catch ( Exception ex )
{
Console.Error.WriteLine( ex.StackTrace );
throw;
}
finally
{
// Delete the job that was created.
if ( job != null )
{
job.Delete();
}
// Delete the path that was created.
if ( path != null )
{
path.Delete();
}
}
}
}
}