ContentDeploymentJob Class

Defines details of a content deployment job.

Namespace:  Microsoft.SharePoint.Publishing.Administration
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class ContentDeploymentJob : DisposableListItemWrapper

A content deployment job consists of the following properties.

Property Name

Description

Name

Provides the name of the content deployment job.

Description

Describes the content deployment job.

Path

Provides the path associated with this content deployment job.

JobType

Defines whether this is a full or partial content deployment.

IsRecurring

Defines whether this is a single or recurring content deployment.

NotificationSettings

Defines whether and when to send e-mail notification when the content deployment succeeds or fails.

ExportMethod

Determines whether to export all changes at one time or incrementally.

using System;
using Microsoft.SharePoint.Publishing.Administration;
using Microsoft.SharePoint;

namespace Microsoft.SDK.SharePoint.Samples.ContentDeployemnt
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("starting sample tests execution...");

            #region ContentDeploymentJob.SqlSnapshotSetting example
            
            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.SqlSnapshotSetting example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // To compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                // set the job to create and use a Sql Snapshot for export
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.CreateNew;
                job.Update();

                try
                {
                    // the job will run using a newly created sql snapshot for export operation
                    job.Run();

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // restore the job's settings back to default
            // ---------------------------------------------------------------------------------------
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.None;
                job.Update();
            }

            #region ContentDeploymentJob.HostingSupportEnabled example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.HostingSupportEnabled example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // To compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.HostingSupportEnabled = true;
                job.Update();
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // restore the job's settings back to default
            // ---------------------------------------------------------------------------------------
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.HostingSupportEnabled = false;
                job.Update();
            }

            #region ContentDeploymentJob.Run() example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run() example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // execute this Content Deployment Job synchronously
                    job.Run();

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            #region ContentDeploymentJob.Run(bool, DateTime) example
            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run(bool, DateTime) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a job was recently successfully executed (so that the time of the
            //   last successfull run - 1 hour falls within the WSS change log window)
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // executing the content deployment job synchronously, specifying the 
                    // deploySinceTime 1 hour prior to the last successfull run
                    job.Run(false, job.LastSuccessfulDeploymentTime.Subtract(new TimeSpan(1, 0, 0)));

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            #region ContentDeploymentJob.Run(bool, string) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run(bool, string) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a Sql snapshot (of the source content DB) named 'yourSnapshot' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // execute the content deployment job synchronously, specifying an existing
                    // Sql snapshot to run export against
                    job.Run(false, "yourSnapshot");

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }
            
            #endregion

            #region ContentDeploymentJob.Run(bool, DateTime, string) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run(bool, DateTime, string) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a Sql snapshot (of the source content DB) named 'yourSnapshot' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                // set the job to create and use a Sql Snapshot for export
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.CreateNew;
                job.Update();

                try
                {
                    // execute this Content Deployment job synchronously, using a specified Sql Snapshot for export,
                    // with the default behavior in regard to what changes are propagated to target
                    // even through the SqlSnapshotSetting is set to ContentDeploymentSqlSnapshotSetting.CreateNew
                    // for this job, it will be ignored and the specified snapshot will be used instead.
                    job.Run(false, DateTime.MinValue, "yourSnapshot");

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // restore the job's settings back to default
            // ---------------------------------------------------------------------------------------
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.None;
                job.Update();
            }

            #region ContentDeploymentJob.Test() example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Test() example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // performs a synchronous test run for this job
                    job.Test();

                    Console.WriteLine("Job's test run completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            #region ContentDeploymentJob.Test(string) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Test(string) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a Sql snapshot (of the source content DB) named 'yourSnapshot' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // performs a synchronous test run for this job, specifying an existing
                    // Sql snapsjhot to run export against
                    job.Test("yourSnapshot");

                    Console.WriteLine("Job's test run completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            #region ContentDeploymentJob.Test(bool, string) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Test(bool, string) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a Sql snapshot (of the source content DB) named 'yourSnapshot' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                // set the job to create and use a Sql Snapshot for export
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.CreateNew;
                job.Update();

                try
                {
                    // performs a synchronous test run for this job, using a specified Sql Snapshot for export
                    // even through the SqlSnapshotSetting is set to ContentDeploymentSqlSnapshotSetting.CreateNew
                    // for this job run, it will be ignored and the specified snapshot will be used instead.
                    job.Test(false, "yourSnapshot");

                    Console.WriteLine("Job's test run completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // restore the job's settings back to default
            // ---------------------------------------------------------------------------------------
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.None;
                job.Update();
            }

            #region ContentDeploymentJob.Test(bool) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Test(bool) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // performs a test run for this job asynchronously
                    // when the call returns the job might not have finished yet
                    job.Test(true);

                    Console.WriteLine("Job's test run started. Job's status is: " + job.LastStatus.ToString());
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // wait till the job's done
            // ---------------------------------------------------------------------------------------
            ContentDeploymentJobStatus status = ContentDeploymentJobStatus.NotAvailable;
            do
            {
                using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
                {
                    status = job.LastStatus;
                }

                System.Threading.Thread.Sleep(30 * 1000); // 30 secs
            }
            while ((status == ContentDeploymentJobStatus.TestSuccess || status == ContentDeploymentJobStatus.TestFailure) == false );

            #region ContentDeploymentJob.Run(bool) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run(bool) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // execute this Content Deployment Job asynchronously
                    // when the call returns the job might not have finished yet
                    job.Run(true);

                    Console.WriteLine("Job's execution started. Job's status is: " + job.LastStatus.ToString());
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            Console.WriteLine("--------------------------------------");
            Console.WriteLine("sample tests completed. Press any key:");
            Console.ReadKey();
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: