SharePoint 2013 Provider Hosted App Timer Job (Schedule Job)

The requirement is for a timer job and a custom SharePoint 2013 application. Here you cannot use a Full Trust SharePoint solution since it must be flexible enough to scale up to SharePoint Online and Azure Cloud.

So the chosen solution is to develop a Provider Hosted Application with a timer job. (The assumption is that you already have a provider hosted app deployed on IIS.)

The timer job on a provider hosted application (remote IIS server) is done by having a scheduler task created to run a console application on IIS server.

The console application has the code to update the SharePoint data on a schedule.

The following is the main procedure involved.

Step 1

Create a new Windows desktop console application.

console application

Step 2

Add Microsoft.SharePoint.Client.dll, Microsoft.SharePoint.Client.Runtime.dll and TokenHelper.cs files to the console application.

NewConsoleReferences

Step 3

Add Certificate, client id and issuer id details to the App.config file.

ConsoleCertDetails

Step 4

The console application code should be executed with AppContext instead of user context. (The following is the helper method created to return AppContext.)

ConsoleCode

Step 5

Once you build the console application, you will get a .exe file and that must be scheduled to be triggered by the Windows Task Scheduler.

NewTask

The same code base can be used to create a new web job on Azure Cloud to make it work in the cloud and SharePoint online.

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now