OPEN TO WORK

Available for new opportunities! Let's build something amazing together.

Adding Properties to Timer Jobs

Timer Jobs Visual Studio
post

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

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.

Related articles

Report issues or make changes on GitHub

Found a typo or issue in this article? Visit the GitHub repository to make changes or submit a bug report.

Comments

Elio Struyf

Solutions Architect & Developer Expert

Loading...

Let's build together

Manage content in VS Code

Present from VS Code