Alert This post is over a year old, some of this information may be out of date.

Adding Properties to Timer Jobs

Adding properties to timer jobs could be handy if you want to set the reference to a particular site collection, or if you want to set some parameters that are needed to run the job.

You could add these properties just like you would add properties to a SharePoint site.

The following code can be used to add a property to the timer job at the creation process.

// Create new timer job
TimerJob timerJob = new TimerJob("TimerJobName", site.WebApplication);
// Add property to timer job
timerJob.Properties.Add("Property_Name", "Property_Value");

To read the property in the timer job, you could use the following code.

String propertyValue = (string)Properties["Property_Name"];

Most of the time I use these properties to specify the site collection for which the timer job needs to run, or define a value for querying items.


Back to top