0

I have created a custom timer job and deployed it to all web applications. In a custom central administration application page, I would like to show links to this timer job (e.g. 2 links if there are 2 web applications), i.e. to timer job settings to make it easier for the user to find the job. When user clicks the link, I'd like to open the same timer job settings/schedule page that opens when you navigate to it via Central Administration : Job Definitions.

How can I construct URLs that will point to my custom timer jobs settings? Class implementing SPFeatureReceiver has GUID assigned to it, but I don't know how to use this to get a full link like:

http://srvr/_admin/JobEdit.aspx?JobId=ffccdd35-4444-4b22-b47b-73bf7039f777

Note that the GUID in the URL is not the same as the GUID provided in code, as each web app will have a different URL to the timer job settings. Can the URL somehow be obtained via SPWebApplication?

3

For every web application you can do the following:

  1. Get your timer job definition (SPJobDefinition) from SPWebApplication.JobDefinitions
  2. Get the guid:

    string jobDefID = SPJobDefinition.Id.ToString();
    
  3. Add the guid in the query string

    http://srvr/_admin/JobEdit.aspx?JobId=jobDefID
    
  • Do you know how I can get the http://srvr/_admin/JobEdit.aspx URL programatically? I can use Microsoft.SharePoint.Administration.SPAdministrationWebApplication.Local.Sites[0] to get http://srvr/, but how about the other part - is it always fixed and can therefore I just hardcode it? – w128 Apr 18 '14 at 8:25
  • 1
    _admin/JobEdit.aspx is always the same. It is an application page in Admin folder in SharePoint Root folder. – Naim Murati Apr 18 '14 at 8:58
1

This is how I did it:

SPWebApplication webApp = SPWebApplication.Lookup(new Uri(webAppUrl));

var customJob = (from job in webApp.JobDefinitions where job.Name == "MyTimerJobName" select job).Single(); // for some reason wont't work if I try to get the job using [name]

string jobUrl =  Microsoft.SharePoint.Administration.SPAdministrationWebApplication.Local.Sites[0].Url + "/_admin/JobEdit.aspx?JobId=" +  timerJob.Id.ToString();
  • Anyone knows why var customJob = (from job in webApp.JobDefinitions where job.Name == "MyTimerJobName" select job).Single(); works and why webapp.JobDefinitions["MyTimerJobName"] under SP 2013 does NOT work? – BOG Feb 23 '16 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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