I have not been able to determine why my custom timer job is failing. I am able to run the Execute() method from a button click, but not via the timer job.
Here is the error:
Here is my code for FileUploadTimerJob.cs:
public class FileUploadTimerJob : SPJobDefinition { public FileUploadTimerJob() : base() { } public FileUploadTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType) { this.Title = "File Upload Timer Job"; } public FileUploadTimerJob(string jobName, SPWebApplication webapp) : base(jobName, webapp, null, SPJobLockType.ContentDatabase) { this.Title = "File Upload Timer Job"; } public override void Execute(Guid targetInstanceId) { UploadDocuments(); OrganizeDocuments(); } }
And here is the code for the Feature Event Receiver:
public class FileUploadTimerJobFeatureEventReceiver : SPFeatureReceiver { const string JobName = "New Task Timer"; public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; // make sure the job isn't already registered foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) { if (job.Name == JobName) job.Delete(); } // install the job FileUploadTimerJob job1 = new FileUploadTimerJob(JobName, site.WebApplication); SPMinuteSchedule schedule = new SPMinuteSchedule(); schedule.BeginSecond = 0; schedule.EndSecond = 59; schedule.Interval = 5; job1.Schedule = schedule; job1.Update(); } public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; // delete the job foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) { if (job.Name == JobName) job.Delete(); } }
Any help would be greatly appreciated.
Thanks.
Jason