R – Prevent deletion of Attachments from a SharePoint List Item

attachmentlistsharepoint

We have a custom SharePoint list type. Part of our list's functionality depends on the existence of a specific attachment for each list item. When the user accidentally or intentionally deletes the attachment (named DoNotDelete.fi!) of a list item our functionality for that item is broken. Therefore we would like to prevent user from being able to delete that particular list item attachment (but should be able to edit the list item otherwise).

Can this be achieved through the use of an EventReceiver for this list item? Given that the attachments are stored in the RootFolder of the list, maybe the EventReceiver needs to be attached not to the list item but elsewhere?

Best Answer

Yes, it is possible, I have created such a construction once.

You have to implement the ItemAttachmentDeleting method of an SPItemEventReceiver. See all possible methods here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spitemeventreceiver_members.aspx