سؤال

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

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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);                        
                }
            } 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top