Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am writing an event receiver that will log delete action (time and user only) of a deleted list item. Following is what it looks like.

public class AuditDeleteReceiver : SPItemEventReceiver
    {
        public override void ItemDeleting(SPItemEventProperties properties)
        {

            base.ItemDeleting(properties);
        }

        public override void ItemDeleted(SPItemEventProperties properties)
        {

            base.ItemDeleted(properties);
        }
    }

When I debug it, I find that only on ItemDeleted, I see two problems.

  1. Properties.ListItem is null and there is no other way to find which item is being deleted.
  2. ItemDeleted method is called as soon as item is deleted from list. I want this to be called when its being deleted from the end user recyle bin.

Is there anything that I'm missing?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

You should definitely use the ItemDeleting event, log the delete action, and then remove the log entry if the item is restored from the recycle bin.

It's not a perfect solution, but there simply isn't an event to capture items being purged from the recycle bins.

EDIT: I went back and checked something I wrote a year or so ago...no event fires when the item is restored fromt he recycle bin. Had a timer job that was scanning AllDocs to see if the item was still there and whether or not DeletedTransactionId was still set. If it wasn't there it had been purged, if it was still there with DeletedTransactionId set it was still recycled, and if it was still there with DeletedTransactionId not set then it was restore. When I say scanning, I was doing indexed queries using the item's Id.

share|improve this answer
add comment
  1. This is correct. Properties.ListItem is empty on ItemDeleted, because this is after event and it is fired when the item is already deleted. You should be using ItemDeleting method if you need list item, because it is fired before item is deleted.
  2. This is also correct. There are no event receivers for recycle bin actions.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.