Partager via


Procédure : Déployer du contenu entre des serveurs

Dernière modification : jeudi 21 janvier 2010

S’applique à : SharePoint Server 2010

Cet exemple de code montre comment utiliser le modèle objet pour créer des chemins d'accès et des tâches qui déploient du contenu entre des collections de sites. Ce code part du principe que les collections de sites source et destination se trouvent dans la même batterie de serveurs. Les chemins d'accès peuvent toutefois être configurés entre différentes batteries de serveurs. Les tâches qu'exécute ce code peuvent également être effectuées par le biais de l'interface utilisateur dans l'administration centrale de SharePoint.

Les chemins d’accès connectent des collections de sites sources et de destination ; les tâches contrôlent quel contenu est copié et quand il est copié. Microsoft SharePoint Server 2010 ne prend en charge que le déploiement source-vers-destination, et pas le déploiement de plusieurs sources vers une destination ou le redéploiement d’un contenu de la destination vers la source. Le déploiement est incrémentiel par défaut et configuré par un administrateur central.

L'exemple suivant montre comment spécifier les paramètres de chemin d'accès et de tâche, configurer le déploiement de contenu pour cette batterie de serveurs, et créer un chemin de déploiement et une tâche associée au chemin d'accès que vous avez créé.

Exemple

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();
                }
            }
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text

Imports 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.

    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            Dim example As New DeploymentExample()
            example.Invoke()
        End Sub
    End Class

    Friend Class DeploymentExample
        Public Sub Invoke()

            ' Path settings
            Dim pathName As String = "My Deployment Path"
            Dim sourceServerUri As New Uri("https://server")
            Dim sourceSiteCollection As String = "/"
            Dim destinationAdminUri As New Uri("https://server:8080")
            Dim destinationServerUri As New Uri("https://server:81")
            Dim destinationSiteCollection As String = "/sites/deploymentdestination"

            ' Job settings
            Dim jobName As String = "My Deployment Job"

            Dim path As ContentDeploymentPath = Nothing
            Dim job As ContentDeploymentJob = Nothing

            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.
                Dim config As ContentDeploymentConfiguration = 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.
                Dim allPaths As ContentDeploymentPathCollection = 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 ex As Exception
                Console.Error.WriteLine(ex.StackTrace)
                Throw
            Finally
                ' Delete the job that was created.
                If job IsNot Nothing Then
                    job.Delete()
                End If
                ' Delete the path that was created.
                If path IsNot Nothing Then
                    path.Delete()
                End If
            End Try
        End Sub
    End Class
End Namespace

Voir aussi

Tâches

Procédure : Personnaliser le déploiement pour scénarios déconnectés

Concepts

Déploiement de contenu entre serveurs