Custom SharePoint Job Definitions


To Create Custom job definition follow the following steps:
1 – Create a new class inherit from Microsoft.SharePoint.Administration.SPJobDefinition
2 – Make this class public
3 – Add three public constructors which is the same of the parent for example:
public CustomJob(): base()
this.Title = “Custom Job”;

public CustomJob(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType)
this.Title = jobName;

public CustomJob(string jobName, SPWebApplication webApplication): base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
this.Title = jobName;
4 – Override execute method which contain all the logic of the job
5 – Add new application feature
6 – Add Feature Event receiver to the new feature
7 – In activation receiver register your custom job for example
public override void FeatureActivated(SPFeatureReceiverProperties properties)
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
CustomTimerJob.CustomJob myJob = new CustomTimerJob.CustomJob(“New Job”,webApp);
SPDailySchedule schedule = new SPDailySchedule();
schedule.BeginHour = 1;
schedule.EndHour = 2;
myJob.Schedule = schedule;
8 – In feature deactivate remove your custom job


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s