Saturday 31 October 2015

Steps to create Timer Job and Event Receiver

Timer Job :

Timer Job is the automated schudled task , which runs in the background of SharePoint.

Steps to create Timer Job :
(1) Create Empty SharePoint Solutions.
(2) Select Farm Solution and then validate the Site.
(3) Create New class ... Inherite it with the SPJobDefination Class
(4) Define three diffrent type of constructors of that class
(5) Also Override the Execute method => Which contains the actual code/ Bussiness logic we need to execure

(6) Now, we need to cretae Feature and also need to add Event Receiver ...!!!
(7) Add feature to the Solution and make its scope to WebApplication level. => Feature task done.
(8) Now, Add Event Receiver and write some code in it which will execute while FeatureActivated and FeatureDeactivated method.
We need to create  CreateJob and DeleteJob Functions here and then we need to call the class of which we just created.
We also need to Schedule calls in to job.schedule class to the timer job class.
Also, we can set the time for fire the Timer job here.

(9) And then deploy the solution .. timer job is deployed .
=======================================================

 Event Receiver :

(1) For this we need to add the Event Receiver Template in the solution.
(2) We need to select, what is the source for the event receiver... after that we need to select the method on which we need to fire the code / Business Logic.
(3) We can also add these methods after wards as required , by go in the property window for the event receiver.
(4) To get the ListItem , we can use the [SPEventProperties]properties parameter of that method like properties.ListItem["FeildName"]

To get the current site url , we can get the => properties.site.openWeb() -> Will give the current web Url.

(5) If we need to fire the Event Receiver to some specific list only, then we can set the List
<Receivers ListUrl="Lists/Facilities" > , in the element.xml file
after that the event receiver will only fire on that list only.
=> We can also check this while execute the code by => properties.ListTilte = "" => and then we can execute the code.

(6) Try to put the feature of the event receiver separate.

============================


No comments:

Post a Comment