问题
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.
回答1:
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.
回答2:
You could check the Created Date of the item. Items from the Recycle bin should have a previous created date.
回答3:
Items in the recycle bin have a DeletedDate that may be available in the properties.BeforeProperties
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/479817/how-to-detect-the-item-restore-on-a-itemadded-event-on-sharepoint