Upload
anh-quan-tran-doan
View
224
Download
0
Embed Size (px)
Citation preview
8/8/2019 Working With Event Handlers in Share Point 2007
1/20
Working with Event Handlers inSharePoint 2007
Dallas SharePoint Developers Group
8 October 2008Miguel Wood, TekFocus
8/8/2019 Working With Event Handlers in Share Point 2007
2/20
Introducing Event Handlers
An event handler is a Microsoft .NET assemblycontaining one or more classes handling events thatare triggered by Microsoft SharePoint Products andTechnologies Avoid deletion of task whennot completed yet
Audit any change thatoccurs to task
Start custom processingwhen priority is changed to
High
Prevent the deletion of a
column for this list
8/8/2019 Working With Event Handlers in Share Point 2007
3/20
What Type of Events?
Events triggered for lists, document libraries, contenttypes, and sitesEvents supported for incoming e-mail messagesSupport for synchronous events and asynchronous events
Synchronous events occur before the fact and are cancelable
Events are used in other scenarios
Custom policies Features
8/8/2019 Working With Event Handlers in Share Point 2007
4/20
Scope of EventsScopeScope DescriptionDescription Base ClassBase Class
Item in a list orlibrary
Actions users can do in a list include adding,modifying, deleting, check-in and check-out, ...
SPItemEventReceiver
List or library Trap changes to entities of list schema events,
supporting list schema operations and the addition orremoval of content types.
SPListEventReceiver
Web Events fired at the level of the site (e.g. adding andremoving sites)
SPWebEventReceiver
Email Provides a method for trapping the event when a listreceives an e-mail message (EmailReceived)
SPEmailEventReceiver
Feature Trap the activation, deactivation, installation, oruninstalling of a Feature
SPFeatureReceiver
8/8/2019 Working With Event Handlers in Share Point 2007
5/20
8/8/2019 Working With Event Handlers in Share Point 2007
6/20
Development Steps
Create Class Library Microsoft Visual Studio extensions for Widows
SharePoint Services (VSeWSS) provide an itemtemplate for event receiver classes
Inherit from one of the base classesImplement one of the event handlers
Register the event handler VSeWSS by default register using Feature Programmatically target one instance
8/8/2019 Working With Event Handlers in Share Point 2007
7/20
Why an Event Handler?
lex ata alidati n ( ri r t edits eing saved)
Filling fields (c lu ns) with external syste data rc lex calculati ns
L gging events t external syste s (file syste , cust
data ase, etc.)
Sending c nfir ati n e ails
8/8/2019 Working With Event Handlers in Share Point 2007
8/20
SharePoint 2003 v. SharePoint 2007Event Handlers
In SharePoint 2003, event handlers were often used for simpleworkflow applications for document or form libraries (the only list
types that supported event handling in SharePoint 2003).
In SharePoint 2007, Windows Workflow Foundation (WF) from the.NET 3.0 framework is used for creating both sequential and statemachine workflows. You should avoid creating highly complex eventhandlers in SharePoint 2007. As a general rule, if your event handlermust perform more than one or two operations, you should considerusing a workflow rather than an event handler.
8/8/2019 Working With Event Handlers in Share Point 2007
9/20
Workflow or an Event Handler?
WorkflowsAre most appropriate forlong-running processesthat may span minutes,hours, or days, andinvolved many individuals(actors)Could be used to respondto list events in real time
Event HandlersRespond in near real-timeto user-initiated actionson a listCould be used to piecetogether workflows
Very simple workflowsmay be easier toimplement as an eventhandler
8/8/2019 Working With Event Handlers in Share Point 2007
10/20
Event Handler Basics inSharePoint 2007
S ort for all list ty es
More events s orted
Two ty es of events ex osedSynchronous event handlers fire before an event isprocessed by SharePoint (e.g. ItemUpdat ing ) A synchronous event handlers fire after an event isprocessed by SharePoint (e.g. ItemUpdat ed )
8/8/2019 Working With Event Handlers in Share Point 2007
11/20
Windows SharePoint Services
.NET Assembly
SPEventReceiver Class Hierarchy
System.Object
Microsoft.SharePoint.SPEventReceiverBase
Microsoft.SharePoint.
SPWebEventReceiver
Microsoft.SharePoint.
SPListEventReceiver
Microsoft.SharePoint.
SPItemEventReceiver
Microsoft.SharePoint.SPWorkflowLibraryEventReceiver
8/8/2019 Working With Event Handlers in Share Point 2007
12/20
Windows SharePoint Services.NET Assembly
SPEventProperties Class Hierarchy
System.Object
Microsoft.SharePoint.
SPEventPropertiesBase
Microsoft.SharePoint.
SPWebEventProperties
Microsoft.SharePoint.
SPListEventProperties
Microsoft.SharePoint.
SPItemEventProperties
8/8/2019 Working With Event Handlers in Share Point 2007
13/20
Key EventReceiver Public Methods
SPWebEventReceiver
SiteDeletedSiteDeletingWebDeletedWebDeletingWebMovedWebMoving
SPListEventReceiver
FieldAddedFieldAddingFieldDeletedFieldDeletingFieldUpdatedFieldUpdating
SPItemEventReceiverItemAddedItemAddingItemAttachmentAddedItemAttachmentAddingItemAttachmentDeletedItemAttachmentDeleting
ItemChecked InItemCheckedOutItemChecking InItemCheckingOutItemDeletedItemDeletingItemFileConvertedItemFileMovedItemFileMovingItemUncheckedOutItemUncheckingOutItemUpdatedItemUpdating
8/8/2019 Working With Event Handlers in Share Point 2007
14/20
EventProperties Class Properties
SPWebEventPropertiesCancelErrorMessageEventTypeFullUrlNewServerRelativeUrl
ReceiverDataServerRelativeUrlSite IdStatusUserDisplayNameUserLoginNameWebWeb Id
CancelErrorMessageEventTypeFullUrlNewServerRelativeUrl
ReceiverDataServerRelativeUrlSite IdStatusUserDisplayNameUserLoginNameWebWeb Id
SPListEventPropertiesCancelErrorMessageEventTypeFieldFieldName
FieldXmlListListIdListTitleRecieverDataSite IdStatusUserDisplayNameUserLoginNameWebWeb IdWebUrl
CancelErrorMessageEventTypeFieldFieldName
FieldXmlListListIdListTitleRecieverDataSite IdStatusUserDisplayNameUserLoginNameWebWeb IdWebUrl
SPItemEventPropertiesAfterPropertiesAfterUrlBeforePropertiesBeforeUrlCancel
ContextCurrentUser IdErrorMessageEventTypeListIdListItemListItem IdListTitleReceiverDataRelativeWebUrlSite IdStatusUserDisplayNameUserLoginNameVersionlessWebUrlZone
AfterPropertiesAfterUrlBeforePropertiesBeforeUrlCancel
ContextCurrentUser IdErrorMessageEventTypeListIdListItemListItem IdListTitleReceiverDataRelativeWebUrlSite IdStatusUserDisplayNameUserLoginNameVersionlessWebUrlZone
8/8/2019 Working With Event Handlers in Share Point 2007
15/20
Feature Receivers
Events are triggered when a Feature is Installed Uninstalled
Activated Deactivated
public class FeatureReceiver : SPFeatureReceiver{
public override void Feature Installed(SPFeatureReceiverProperties properties) {}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {}
public override void FeatureActivated(SPFeatureReceiverProperties properties) {}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) {}
}
8/8/2019 Working With Event Handlers in Share Point 2007
16/20
CREATING A CALCULATED FIELD BYUSING AN EVENT HANDLER
Demo
8/8/2019 Working With Event Handlers in Share Point 2007
17/20
Process Flow
8/8/2019 Working With Event Handlers in Share Point 2007
18/20
PREVENTING DELETION BY USINGAN EVENT HANDLER
Demo
8/8/2019 Working With Event Handlers in Share Point 2007
19/20
Process Flow
8/8/2019 Working With Event Handlers in Share Point 2007
20/20
Resources
Visual Studio Extensions for Windows SharePoint Services, v1.1(www.microsoft.com/downloads/details.aspx?Family ID=3E1DCCCD-1CCA-433A-BB4D-97B96BF7AB63&displaylang=en )
Windows SharePoint Services 3.0 SP1 Developer Evaluation Image(www.microsoft.com/downloads/details.aspx?Family ID=1beeac6f-2ea1-4769-9948-74a74bd604fa&DisplayLang=en )Application Development Exams
70-541 TS: Windows SharePoint Services 3.0
(www.microsoft.com/learning/exams/70-541.mspx )70-542 TS: Microsoft Office SharePoint Server 2007(www.microsoft.com/learning/exams/70-542.mspx )