Mike Hodnick's Blog

Execute SharePoint Content Deployment (and Quick Deploy) Jobs Programmatically

This is arguably one of the easiest tasks you can perform in code as a SharePoint developer, but not very well known or documented. Start off by referencing the Microsoft.SharePoint.Publishing assembly. The rest is cake:

// assume we're using the
// Microsoft.SharePoint.Publishing.Administration namespace

ContentDeploymentJobCollection jobs = ContentDeploymentJob.GetAllJobs();

foreach (Job job in jobs)
{
  Console.WriteLine(job.Name);
  job.Run();
}

The ContentDeploymentJob class also has a GetAllQuickDeployJobs() method to return only Quick Deploy jobs.

The ContentDeploymentJob class hosts the expected methods and properties you'd find on a job, such as Name, Description, LastStatus, Run(), and Test() (among others).

Technorati Tags: