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
SPSite("http://your_site");
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == "Workflow Auto Cleanup")
{
job.Execute(new
Guid("B29B5AC8-E739-4105-A0F0-D3C05D7E6F64"));
//Replace this GUID with your content database GUID
}
}
That's it. You have started your job through coding.
No comments:
Post a Comment