Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Running SharePoint timer job programmatically using non-farm admin users

$
0
0

Hi All,

I am trying to start a custom timer job programmatically on click of a button in my custom web part(see the below code).The code works fine if run using a farm admin account, but get access denied issue otherwise.

How do I impersonate the code as a farm admin account? Is there a better workaround?

SPWeb web =SPContext.Current.Web;

               SPSite curSite = newSPSite(web.Url);

               SPWebApplication MainWebApp = SPWebApplication.Lookup(new Uri(web.Url));

               var traceJob = (from jobDefinitionin MainWebApp.JobDefinitions

                               where jobDefinition.DisplayName == "Custom Timer Job"

                               select jobDefinition).SingleOrDefault();

               if (traceJob != null)

                   traceJob.RunNow();

}

Regards,

Ameya


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>