Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Access Denied in Timer Job

$
0
0

I have the following code in a timer job. I got "Access Denied" on the last line to access the list although I used "SPSecurity.RunWithElevatedPrivileges". The variable strtemp return a null value. If I runs the same code as a windows form application, it works without any problem. The strtemp returns my user name. I will appreciate if someone can let me know what I did wrong. Many thanks.

/////////////////////////////////////////////////////////////////

namespace UpdateLocationProgram

{

    public class CustomTimerJob : SPJobDefinition

    {

        //veriable

        int n;

        public const string jobName = "AL_Daily_Proc";

        public CustomTimerJob ():base()

        {

        }

        public CustomTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)

        :base (jobName, service, server, targetType)

        {

        }

        public CustomTimerJob(string jobName, SPWebApplication webApplication)

            : base(jobName, webApplication,

null, SPJobLockType.Job)

        {

            this.Title = "AL Daily Process";

        }

        public override void Execute(Guid targetInstanceId)

        {

            //connect to local sp

            SPSecurity.RunWithElevatedPrivileges(delegate()

            {

               using (SPSite oSPsite = new SPSite("http://localhost/"))

               {

                   using (SPWeb oSPWeb = oSPsite.OpenWeb())

                   {

                       //////////////////////////////

                       ///update program code

                       //////////////////////////////

                       string strtemp = oSPWeb.CurrentUser.ToString();

                       oSPWeb.AllowUnsafeUpdates = true;

                       SPList aList = oSPWeb.Lists["AcctCode"];


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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