SharePoint 2010: Start Timer Job from Site Collection

SharePoint 2010: Start Timer Job from Site Collection



Introduction

 Microsoft SharePoint 2010 timer jobs are executable tasks that run on one or more servers at a scheduled time. They can be configured to run exactly one time, or on a recurring schedule. We have deployed such a timer job in Central Administration.

Recently I came across a requirement where the business users wanted an option on a page to start the timer job from Site Collection , so that they do not have to request the support team that manages the farm to start the timer job at any specific time on demand.
However, When we try to access a timer job from site collection, it throws "Access denied" error.
So here is the solution to Start Timer Job from Site Collection instead of Central Admin.



Solution

In order to access the Timer job in Site Collection, we need to set the web service property "RemoteAdminstratorAccessDenied" to false.

SPWebService.ContextService.RemoteAdministratorAccessDenied = false;

Once this is done, and we try to start the timer job from site collection it works like a charm. Here is a sample where we do just this on a button click from a site collection page.

using (SPSite site = new SPSite("site")){
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
   if (job.Name == "Timerjobname"){
      job.RunNow();
      }
}}

Happy Coding!

Other languages

This article is also available in the following languages:

Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (2 items)