I know that when an item is restored from the recycle bin, the ItemAdded event is fired. However, how can I detect if the item added comes from the recycle bin or if it is a new file.
5 Answers
This is a very old thread, but it comes up in the top results for searches on the topic.
From my experiments with SP2010, it looks like properties.AfterProperties is empty when the item is coming from the Recycle Bin, whereas it is fully populated on an actual new item.
So, a simple block such as this would do the trick:
if (!properties.AfterProperties.Cast<DictionaryEntry>().Any())
{
// From Recycle Bin!
}
else
{
// This item is really new.
}
I have not tested MOSS or SP2013 yet.

- 175
- 7
-
It works for me. I would add that it is in the ItemAdded event. My solution was: public override void ItemAdded(SPItemEventProperties properties) { if (!properties.AfterProperties.GetEnumerator().MoveNext()) { //From recycle bin } } – Adrian Stanisławski Nov 23 '18 at 08:46
You could check the Created Date of the item. Items from the Recycle bin should have a previous created date.

- 2,572
- 3
- 26
- 44
-
That's a practical solution (if you convert them to milliseconds there is little chance of error), but relying on DateTime comparisons seems kludgy (you need to involve CultureInfo and string to date conversions). See my answer below for – Louis Aug 23 '13 at 15:39
Items in the recycle bin have a DeletedDate that may be available in the properties.BeforeProperties

- 14,175
- 5
- 41
- 64
If you want detect it manually, then check the property of the document: there created data is different. For a document even if it was thrown into recycle bin the created data is the same. If you want do it through kind of workflow then you can set property as a benchmark. more detail please find it yourself.
Check the value of the SPItemEventProperties.ListItemId property:
- If it is 0, then it is a new item;
- If it is not 0, then it is an item that is restored from the Recycle Bin.

- 3,945
- 3
- 38
- 56
-
The ItemAdded event happens *after* the list item has been created and will have a ListItemId in both cases. Your answer is correct for the ItemAdding event only. – Chloraphil Sep 07 '11 at 18:20