This topic has not yet been rated - Rate this topic

SPItemEventReceiver.ItemAttachmentAdded Method

Handles the asynchronous event that occurs after an attachment is added to an item.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
public virtual void ItemAttachmentAdded(
	SPItemEventProperties properties
)

Parameters

properties
Type: Microsoft.SharePoint.SPItemEventProperties
The properties of the event handler.
Exception Condition
ArgumentNullException

properties is null.

This event occurs when an attachment is added to a list item, but no other updates occur. The event occurs after the ItemUpdated event if other changes are made to the item.

Before and After properties are guaranteed for postback events on documents, but Before properties are not available for postback events on list items.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
ItemAttachmentAdded thru List Datasheet view
When multiple attachments are added thru datasheet view (of a custom list), it runs in asynchronous threads trying to access the list item at the same time. For example, document 1 and document 2 are added as attachments thru datasheet view and when  OK button is clicked, there will be 2 threads running parallel (executing ItemAttachmentAdded method individually) i.e., for document 1 attached, there will be a thread which will execute for attachment collection (having document 1 only) and for document 2 attached, there will be another thread executing with attachment collection (having both document 1 and document 2). Hence, any update to the list item during this execution is likely to cause a save conflict error or any exception. To resolve any such save conflict, use 'SPEventReceiverDefinition.Synchronization = SPEventReceiverSynchronization.Synchronous' while registering the event receiver. This will cause the threads to execute synchronously without interfering.