10
Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment Object model Features Impersonation

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Embed Size (px)

Citation preview

Page 1: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

Event HandlersEvent Handlers

• Overview

• Classes

• Simple Event Handler from the SDK

• Deployment– Object model– Features

• Impersonation

Page 2: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

OverviewOverview

• Developers can use event handlers to execute custom code before or after events that happen to site collections, sites, lists, or list items

• before = synchronous

• after = asynchronous

Page 3: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

Event Handlers OverviewEvent Handlers Overview

• Event handlers must derive from an appropriate class and implement specific methods to handle the events correctly:

– SPWebEventReceiver – for site and site collection events

– SPListEventReceiver – for list schema events

– SPItemEventReceiver – for list item events

Page 4: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

Classes: SPWebEventReceiverClasses: SPWebEventReceiver

• SiteDeleted Occurs after a site collection has been deleted.

• SiteDeleting Occurs when a site collection is being deleted.

• WebDeleted Asynchronous after event that occurs after an existing Web site is completely deleted.

• WebDeleting Synchronous before event that occurs before an existing Web site is completely deleted.

• WebMoved Asynchronous after event that occurs after an existing Web site has been moved.

• WebMoving Synchronous before event that occurs before an existing Web site has been renamed or moved to a different parent object.

Page 5: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

Classes: SPListEventReceiverClasses: SPListEventReceiver

• FieldAdded Occurs after a field link is added.

• FieldAdding Occurs when a fieldlink is being added to a content type.

• FieldDeleted Occurs after a field has been removed from the list.

• FieldDeleting Occurs when a field is in process of being removed from the list.

• FieldUpdated Occurs after a field link has been updated

• FieldUpdating Occurs when a fieldlink is being updated

Page 6: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

Classes: SPItemEventReceiverClasses: SPItemEventReceiver

• Only asynchronous methods listed

ItemAdded ItemAttachmentAddedItemAttachmentDeletedItemCheckedInItemCheckedOutItemDeletedtemFileConverted   ItemFileMoved ItemUncheckedOutItemUpdated

Page 7: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

Demo: Simple Event Handler from SDKDemo: Simple Event Handler from SDK

Demo: Simple Event Handler from SDK

1. Create an event handler for a list item

2. Override ItemUpdating() to show how to display messages to the user

3. Override ItemAdded() to demo asynchronous events

Page 8: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

DeploymentDeployment

• When event handler is ready, developer must deploy the assembly into GAC (Global Assembly Cache)

• Then developer must register the event in one of the three ways:

– using a feature for a list type– using a feature for a content type– using object model to register to SPWeb or

SPList EventReceivers

Page 9: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

Demo: DeploymentDemo: Deployment

Demo: Deployment

1. Deploy the event handler through the object model

2. Development tips:

a. Each time the change is made, remove and add the dll to GAC, and restart IIS.

b. The eventsink code should be calling other classes that can be tested separately

Page 10: Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Event Handlers Overview Classes Simple Event Handler from the SDK Deployment –Object model

Copyright © 2006 Pilothouse Consulting Inc. All rights reserved.

Impersonation in event handlersImpersonation in event handlers

• Event handlers are executed in the context of the current user

• Use System.Security.Principal.WindowsIdentity to check

• Certain actions will require impersonation