Domanda

I want to know whether it is possible to run SharePoint Timer Job on button click event.

È stato utile?

Soluzione

Yes you can do that but users and application pool in a site collection do not have rights to start a timer job.You need Farm administrator permission.

foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
     {
                 if (job.Name == "JobName")
                  {
                      var strStatus = job.Status;



        // THE ORIGINAL VALUE OF REMOTE ADMINISTRATOR
   var remoteAdministratorAccessDenied = SPWebService.ContentService.RemoteAdministratorAccessDenied;
                              try
                            {
    // SET THE REMOTE ADMINISTATOR ACCESS DENIED FALSE
      SPWebService.ContentService.RemoteAdministratorAccessDenied = false;

                             if (remoteAdministratorAccessDenied == true)
                                            {
         SPWebService myService = SPWebService.ContentService;
          myService.RemoteAdministratorAccessDenied = false;
                        myService.Update();
                          `enter code here`
                           job.RunNow();


                                            }

                                            else
                                            {

                                                job.RunNow();

                                            }


                                        }
                                        catch (Exception ex)
                                        { }

http://dvsivakrishna.blogspot.com/2014/01/this-is-mainly-used-to-run-timer-job-in.html

Altri suggerimenti

Yes, this way even normal users will be able to start a timer job.

            SPSite site = new SPSite("http://site");            
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.DisplayName.Equals("TimerJobName"))
                {
                    job.Execute(Guid.Empty);                        
                }
            } 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top