Part of a project I'm working on involves creating a custom timer job which has some properties which are populated via the feature Template.XML file by default.

However, while this is sufficient for development purposes, it becomes a terrible hassle once it's used on a production server. So I wanted to create a configuration page for the timer job.

I've managed to create a custom Application Page visible in Central Administration. However, I'm struggling to get the actual SPJobDefinition object in the pages' code-behind.

Here's my current code:

        var jobs = new List<SPJobDefinition>();
        jobs.AddRange(SPFarm.Local.Services.SelectMany(s => s.JobDefinitions));
        return jobs.Where(j => j.Name == TimerJobs.SyncTimerJob.JobName).ToList();

The job definitely exists and is being executed, but the above code doesn't return the definition. (I know the above code isn't optimized - I've left it like that to see what results I get!)

What am I doing wrong? How can I get the definition for my custom timer job from an Application Page code-behind deployed in Central Administration?

1 Answer 1


I've found the solution, so I'm posting it in case someone else has the same problem. It turns out I wasn't getting all the job-definitions in the system after all - I still had to check the job definitions for available web sites.

Here's the code:

        jobs.AddRange(SPWebService.ContentService.WebApplications.SelectMany(wa => wa.JobDefinitions));

Now the code can be optimized (by adding .Where to the queries) and should return a custom timer job definition, ready for updating as needed.

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.