I need to periodically execute code that reads and writes ListData within a certain SiteCollection. My first thought was a TimerJob.

Can I create a TimerJob using a SiteCollection-Feature? How can I tell this TimerJob which SiteCollection it should target and how can I access this SiteCollection's data in the TimerJob's code?

While there are many SiteCollections in the parent WebApplication, I only need this TimerJob to process the data of one single specific SiteCollection.

Thank you in advance for any help!

2 Answers 2


Timer Job is executed through SharePoint Timer Services. So there is no concept of Site Collection Scope etc.

You can say on which all servers (in case of multiple server farm) the job should be executed. This can be achieved using the constructor

public CustomTimerJob(string jobName, SPService service): 
      base(jobName, service, null, SPJobLockType.Job) { ...
//Read more about SPJobLockType 

You can use a Feature to install the Timer Job. Inside the Feature Receiver you can create new Timer Object and set the Schedule. Based on the schedule timer job will get executed every (day/x hours/y minutes)

Now each timer object has an Execute method. You need to write your code inside this method.

To target data in a specific Site Collection you can use SPSite object as

using(SPSite sitecollection = new SPSite("http://sitecollectionURL"))
    using(SPWeb web = sitecollection.OpenWeb())
        SPList list = web.Lists["ListName"];
  • Ok, I understand. What would be the easiest way to make the SiteCollection-URL configurable for the timerjob? Hard coded feels really dirty.. Can I pass it to the timerjob using a SiteCollection-Feature?
    – Luke
    Jun 2, 2015 at 12:23
  • Yes. As part of activating the time job using feature receiver you can pass the parameters to the constructor or using a Public Custom Property. Jun 2, 2015 at 12:25

Timer-Jobs have to be deployed in farm scope and also run in that scope. You´d have to connect in your timer-job´s execute-method manually (or hardcoded or any configurable ways you´d like to provide) with the desired SPSite

using (var site = new SPSite(URL);
using (var web = site.openWeb());
enter code here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.