• Save
SPSBMORE 2013 - Getting Started with Event Receivers
Upcoming SlideShare
Loading in...5
×
 

SPSBMORE 2013 - Getting Started with Event Receivers

on

  • 768 views

Slides of my session on SharePoint 2010 Event Receivers at SPSBMORE 2013 in in Room 21 at 03:30 PM. ...

Slides of my session on SharePoint 2010 Event Receivers at SPSBMORE 2013 in in Room 21 at 03:30 PM.
Location :
Loyola University
Timonium Campus
2034 Greenspring Drive
Timonium, MD 21093

Statistics

Views

Total Views
768
Views on SlideShare
767
Embed Views
1

Actions

Likes
0
Downloads
3
Comments
0

1 Embed 1

https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

SPSBMORE 2013 - Getting Started with Event Receivers SPSBMORE 2013 - Getting Started with Event Receivers Presentation Transcript

  • #SPSBMORE @PGBhoyar Presented By: Prashant G Bhoyar Getting Started with Event Receivers in SharePoint 2010 18 May 2013
  • #SPSBMORE @PGBhoyar Who am I?
  • #SPSBMORE @PGBhoyar About today’s Session • Raise your hand if something is not clear • Sharing is Caring • Ask Questions • Giveaway : SharePoint 2010 book if you answer the question in the end • Let the learning begins…
  • #SPSBMORE @PGBhoyar What Will We Cover Today? • What are Event Receivers? • Common business scenarios for event receivers • Event receivers architecture • Developing event receivers • Various approaches to registering event receiver • Common issues and fixes for event receivers • Cancelling events and redirecting users to error pages • Event receivers best practices • When not to use them
  • #SPSBMORE @PGBhoyar What are Event Receivers? • Provides developers an ability to execute custom code against various events that occur during the life cycle of various SharePoint objects • SPSite • SPWeb • SPList • SPListItem • SPContentType
  • #SPSBMORE @PGBhoyar Object Operations Site Collection • Deletion Web • Creation • URL modification • Deletion List • Creation • Deletion • Received an e-mail message Field • Creation • Update • Deletion Item • Creation • Update • Deletion • Check in • Check out • File movement • File conversion • Adding attachment • Deleting attaching Workflow • Start • Completed • Postponed Operations Available to Event Receivers
  • #SPSBMORE @PGBhoyar LessComplexity Examples of Event Receivers in SharePoint • Auditing • Validations • Notifications • Various other Automations
  • #SPSBMORE @PGBhoyar LessComplexity Architecture of Event Receivers • Event Receiver Base Class: Inherit custom event receivers from one of the base classes • SPWebEventReceiver • SPListEventReiver • SPItemEventReceiver • SPWorkflowEventReceiver • SPFeatureReceiver • SPEmailEventReceiver
  • #SPSBMORE @PGBhoyar LessComplexity Event Receivers Base Class Structure
  • #SPSBMORE @PGBhoyar Event receiver base class Available event host types Supported events SPWebEventReceiver •SPSite •SPWeb •SiteDeleting •SiteDeleted •WebAdding •WebProvisioned •WebDeleting •WebDeleted •WebMoving •WebMoved SPListEventReceiver (lists) •SPSite •SPWeb •ListAdding •ListAdded •ListDeleting •ListDeleted SPListEventReceiver (fields) •SPSite •SPWeb •SPList •SPContentType •FieldAdding •FieldAdded •FieldDeleting •FieldDeleted •FieldUpdating •FieldUpdated Event Receiver Base Classes and Supported Events
  • #SPSBMORE @PGBhoyar Event receiver base class Available event host types Supported events SPItemEventReceiver •SPSite •SPWeb •SPList •SPContentType •ItemAdding •ItemAdded •ItemDeleting •ItemDeleted •ItemUpdating •ItemUpdated •ItemFileConverted •ItemFileMoving •ItemFileMoved •ItemCheckingIn •ItemCheckedIn •ItemCheckingOut •ItemCheckedOut •ItemAttachmentAdding •ItemAttachmentAdded •ItemAttachmentDeleting •ItemAttachmentDeleted SPEmailEventReceiver •SPSite •SPWeb •SPList •EmailReceived SPWorkflowEventReceiver •SPSite •SPWeb •SPList •SPContentType •WorkflowStarting •WorkflowStarted •WorkflowCompleted •WorkflowPostponed Event Receiver Base Classes and Supported Events Cont..
  • #SPSBMORE @PGBhoyar Typical Event Receiver Life Cycle
  • #SPSBMORE @PGBhoyar LessComplexity Synchronous and Asynchronous Events • Synchronous events provide an opportunity to act on the event and ability to change the outcome of it (such as canceling the event). • Before Events • Events ending with “ing” • Asynchronous events provide an opportunity to react to an event that just happened • After Events • Events ending with “ed”
  • #SPSBMORE @PGBhoyar LessComplexity Synchronous Events • Gets executed before data is committed to Content Database • Provides an opportunity to perform various pre processing tasks like validations • Provides an opportunity to cancel the event and nothing will get committed to content database • Run in the same process and thread that triggers the event • Avoid using complex time-consuming processing logic inside synchronous events as they block the execution of the current request thread until the event receiver completes its execution • UI will be held up in rendering • Tip: In case of list event receivers, do not try to reference “ID” of the current item that is getting created, since SharePoint assigns ID after the data is committed to Content Database
  • #SPSBMORE @PGBhoyar LessComplexity Asynchronous Events • Gets executed after data is committed to Content Database • Can’t cancel these events • Provides an opportunity to perform various post processing tasks like sending notifications • Run on a background thread and never block the UI thread • To change this behavior update the synchronization property of event receiver to synchronous • Scenario : update the UI with info from post execution of an asynchronous event receiver
  • #SPSBMORE @PGBhoyar LessComplexity SharePoint Events Pipeline • Synchronous events are processed in the same thread of user action. • Asynchronous events are processed on secondary threads.
  • #SPSBMORE @PGBhoyar LessComplexity Custom Event Receivers needs to be deployed and registered with SharePoint. Two options are available. • Declarative by using SharePoint Feature • Pros: Easy to deploy and maintain • Cons: Difficult to develop • Programmatically using Server side object model • Pros : Flexible, Easier to Develop • Cons : Difficult to deploy and maintain Deployment and Registration of Custom Event Receivers
  • #SPSBMORE @PGBhoyar DEMO
  • #SPSBMORE @PGBhoyar LessComplexity Developing Custom List Event Receivers • Set up the solution • Feature Activation • Event Receiver Code • Examples • Event Recursion • Event Cancellation
  • #SPSBMORE @PGBhoyar Best Practices • Always implement Exception Handling • No need to provision new SPWeb, SPSite objects of the current site, already available with properties. • Avoid complex time consuming processing logic • Use declarative approach for registration and deployment • Use sequence number above 10,000 to avoid conflict with SharePoint OOB event receivers • Avoid cascading events receivers
  • #SPSBMORE @PGBhoyar When not to use Event Receivers? • To perform long-running and processor-intensive tasks • Example : document conversion from MS Word to PDF • Alternatives: Timer Jobs, Batch Jobs • To Execute validation logic inside event receivers, which can easily be done on the client side • Alternatives : Use column-level validators to perform client-side validations • To Implement workflow-like process logic. • Alternatives : SharePoint Workflows
  • #SPSBMORE @PGBhoyar LessComplexity Is Event Receiver Right Choice? • Yes if, • OOTB options are not available • No Human Interaction in Automation • Data needs to be updated real time • Not doing complex time-consuming processing logic • No Chain of Events Receivers
  • #SPSBMORE @PGBhoyar References Appendix/Resources Expert SharePoint 2010 Practices By : Sahil Malik, Dan Bakmand-Mikalski, Razi bin Rais and Darrin Bishop MSDN: http://msdn.microsoft.com/en-us/sharepoint/default.aspx http://msdn.microsoft.com/en-us/library/gg749858.aspx http://msdn.microsoft.com/en-us/library/gg981880.aspx http://msdn.microsoft.com/en- us/library/microsoft.sharepoint.spitemeventreceiver.aspx
  • #SPSBMORE @PGBhoyar Questions? Feedback? Contact me:  Twitter: @PGBhoyar  Blog: http://pgbhoyar.wordpress.com (limited contents)  Email: pgbhoyar@gmail.com Thank You Organizers, Sponsors and You for Making this Possible.