Which code segment should you use?

You are creating a Microsoft Windows SharePoint Services application that uses a tasks list.

The application must notify the project manager each time a new task is inserted into the tasks list. You write an event receiver in the class named TaskEventClass and compile the class in the assembly named TaskEventAssembly.

You need to register the event receiver. You also need to ensure that the event receiver is fired only when an item is added to the tasks list.

Which code segment should you use?

You are creating a Microsoft Windows SharePoint Services application that uses a tasks list.

The application must notify the project manager each time a new task is inserted into the tasks list. You write an event receiver in the class named TaskEventClass and compile the class in the assembly named TaskEventAssembly.

You need to register the event receiver. You also need to ensure that the event receiver is fired only when an item is added to the tasks list.

Which code segment should you use?

A.
Public Sub AddEventReceiver(ByVal web As SPWeb)
web.EventReceivers.Add(SPEventReceiverType.ItemAdded, _
“TaskEventAssembly”, “TaskEventClass”)
End Sub

B.
Public Sub AddEventReceiver(ByVal web As SPWeb)
web.Lists(“Tasks”).EventReceivers.Add(SPEventReceiverType._
ItemAdded, “TaskEventAssembly”, “TaskEventClass”)
End Sub

C.
Public Sub AddEventReceiver(ByVal web As SPWeb)
Dim list As SPList = web.Lists(“Tasks”)
list.EventSinkAssembly = “TaskEve ntAssembly”
list.EventSinkClass = “TaskEventClass”
list.EventSinkData = SPEventReceiverType.ItemAdded.ToString
End Sub

D.
Public Sub AddEventReceiver(ByVal web As SPWeb)
Dim list As SPList = web.Lists(“Tasks”)
Dim eventHandler As SPEventReceiverDefinitionCollection = _
web.EventReceivers
eventHandler.Add(SPEventReceiverType.ItemAdded, _
“TaskEventAssembly”, “TaskEventClass”)
End Sub



Leave a Reply 0

Your email address will not be published. Required fields are marked *