That "something more" can be:
- Retrieve information from a database such as filling in the remaining fields of a list based on a CustomerID (assuming you don't have an enterprise license for BDC)
- Call a web service
- Start a workflow
- Perform list data validation
- Convert document to PDF and store in alternative list.
- Access data in another list
- or many other things.
Question arises how does one hook/unhook custom logic to these events. For this refer the code below(code below operates on registering/unregistering events to a SharePoint Document Library):
eventType = SPEventReceiverType.ItemAdding,SPEventReceiverType.ItemDeleted etc...
assemblyName =
ClassName = NameSpace,ClassName
register events
[code]
public static void addEventReceiver(SPList docLib, SPEventReceiverType eventType, string assemblyName, string className)
{
try
{
docLib.EventReceivers.Add(eventType, assemblyName, className);
docLib.Update();
}
catch(Exception ex)
{
// handle or raise exception
}
}
[/code]
un-register events
[code]
public static void removeEventReceivers(SPList docLib, SPEventReceiverType eventType, string assemblyName, string className)
{
try
{
int i;
for (i = 0; i < docLib.EventReceivers.Count; i++)
{
if (docLib.EventReceivers[i].Assembly.Equals(assemblyName)
&& docLib.EventReceivers[i].Class.Equals(className)
&& docLib.EventReceivers[i].Type.Equals(eventType))
{
docLib.EventReceivers[i].Delete();
}
} // looping thru event receivers.
docLib.Update();
}
catch(Exception ex)
{
// handle or raise exception
}
}
[/code]
Here is a list of events on which you can hook your custom code into:
Microsoft.SharePoint.SPWebEventReceiver : "Site Level"
Occurs after a site collection has been deleted. | |
Occurs when a site collection is being deleted. | |
Asynchronous Afterevent that occurs after an existing Web site is completely deleted. | |
Synchronous before event that occurs before an existing Web site is completely deleted. | |
Asynchronous after event that occurs after an existing Web site has been moved. | |
Synchronous before event that occurs before an existing Web site has been renamed or moved to a different parent object. |
· Microsoft.SharePoint.SPListEventReceiver : "List Level"
Occurs after a field link is added. | |
Occurs when a field link is being added to a content type. | |
Occurs after a field has been removed from the list. | |
Occurs when a field is in the process of being removed from the list. | |
Occurs after a field link has been updated | |
Occurs when a field link is being updated |
· Microsoft.SharePoint.SPItemEventReceiver : "List Item Level"
Asynchronous After event that occurs after a new item has been added to its containing object. | |
Synchronous before event that occurs when a new item is added to its containing object. | |
Asynchronous after event that occurs after a user adds an attachment to an item. | |
Synchronous before event that occurs when a user adds an attachment to an item. | |
Asynchronous after event that occurs when after a user removes an attachment from an item. | |
Synchronous before event that occurs when a user removes an attachment from an item. | |
Asynchronous after event that occurs after an item is checked in. | |
Asynchronous after event that occurs after an item is checked out. | |
Synchronous before event that occurs as a file is being checked in. | |
Synchronous before event that occurs after an item is checked out. | |
Asynchronous after event that occurs after an existing item is completely deleted. | |
Synchronous before event that occurs before an existing item is completely deleted. | |
| |
Occurs after a file is moved. | |
Occurs when a file is being moved. | |
Synchronous before event that occurs when an item is being unchecked out. | |
Synchronous before event that occurs when an item is being unchecked out. | |
Asynchronous after event that occurs after an existing item is changed, for example, when the user changes data in one or more fields. | |
Synchronous before event that occurs when an existing item is changed, for example, when the user changes data in one or more fields. |
Cheers,
Sandeep
No comments:
Post a Comment