Friday, August 8, 2008

Starting timer job through coding

Hi All,

May times you require to start a timer job from coding.

First to check about your timer job definitions, you need to go to Central Administration -> Operations->Timer Job Definitions.

You will find all Titles that are timer job definitions. These are the "Name" Property that you can set while coding. You can also see that those denifitions belongs to which web application in Web Application column there and also scheduled Type , At what durations they run.

If you want to start any of the job definition programatically, you first need to know the Content database's GUID.

To Get the GUID of Content Database of your web application , go to the following path,

Central Administration > Application Management > Content Databases.

Here you will find each respective web application's content database. Right click that content database, Click on properties and then you will find DatabaseId - {"SomeString"}.

This String will contain the Encoded character, replace them with Proper character like %2D is actually a - sign.

Once you have GUID. keep it with you, that will be requires at the time of coding.

Now you have code to write :

SPSite site = new

foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)

if (job.Name == "Workflow Auto Cleanup")

//Replace this GUID with your content database GUID



That's it. You have started your job through coding.

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to