I have a custom Timer Job that runs on every Monday. However, I want to be able to run the timer job manually outside of Central admin. but I dont want to use PowerShall or stsadm. Can I put a link or a button on my site collection/SharePoint site and when someone clicks that link the timer job should run?

Thanks, Vikram

  • Just to be sure - SharePoint 2010/2013 or SharePoint 2007? – BlueSoul Mar 8 '13 at 10:41

You can write similar code on your button click :

      SPSite site = new SPSite([your-site-url]);

        foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            if (job.Name == "YouTimerjobname")
|improve this answer|||||
  • 1
    using(SPSite site = new SPSite([your-site-url])) should be used as you are creating a new instance of SPSite that needs to be disposed. – Muhammad Raja Mar 8 '13 at 10:27
  • I used the code you gave and created an webpart with a button. But when I click the button i get a error "The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. "?? – Vikram Mar 9 '13 at 5:09
  • 1
    try the code using SPsecurity.RunWithElevatedPrivileges – Amit Kumawat Mar 9 '13 at 5:24
  • this is the code i am using now, can plz tell me wht iam doing wrong? – Vikram Mar 9 '13 at 6:31
  • protected void btn_sendEmail_Click(object sender, EventArgs e) {SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite("xxxxxxxsiteURLxxxxx")) {foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) {if (job.Name.Equals("Email")) job.RunNow(); }} }); } – Vikram Mar 9 '13 at 6:49

You can start a timer job by code. So you can create a web part with a button. When a user clicks the button the 'onclick' code of the button starts the job.

Add the web part to a page and/or set security on the page so that only you can access it.

|improve this answer|||||

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.