次の方法で共有


[方法] サーバー間でコンテンツを展開する

このコード サンプルは、オブジェクト モデルを使用して、サイト コレクション間でコンテンツを展開するパスおよびジョブを作成する方法を示しています。このコードは、展開元のサイト コレクションと展開先のサイト コレクションが同じサーバー ファーム内にあることを前提としています。ただし、異なるサーバー ファーム間のパスを構成することもできます。このコードが実行するタスクは、SharePoint サーバーの全体管理のユーザー インターフェイスを介して実行することもできます。

パスは、展開元のサイト コレクションと展開先のサイト コレクションを接続します。ジョブは、コピーされるコンテンツおよびコピーされるタイミングを制御します。Microsoft Office SharePoint Server 2007 は、展開元から展開先への展開のみをサポートし、複数の展開元から 1 つの展開先への展開や展開先から展開元へのコンテンツ展開はサポートしません。展開は、既定では増分的に行われ、サーバー管理者によって構成されます。

以下の例は、パスおよびジョブ設定を指定し、このファームのコンテンツ展開を構成し、展開パスおよび作成したパスに関連付けられたジョブを作成する方法を示しています。

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

See Also

タスク

[方法] 切断されたシナリオで展開をカスタマイズする

概念

サーバー間のコンテンツを展開する