Adding Properties to Timer Jobs
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 jobTimerJob timerJob = new TimerJob("TimerJobName", site.WebApplication);// Add property to timer jobtimerJob.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
Creating a NuGet Package to Automate the SharePoint Solution Creation Process.
Downgrade a SharePoint 2010 Visual Web Part to SharePoint 2007
Re-add the My Links Functionality as in SharePoint 2007 to Your 2010 Site
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
Let's build together
Manage content in VS Code
Present from VS Code