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.
我知道当从回收站恢复项目时,会触发ItemAdded事件。但是,如何检测添加的项目是来自回收站还是新文件。
5 个解决方案
#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.
从我使用SP2010的实验中,它看起来像properties.AfterProperties在项目来自回收站时为空,而它完全填充在实际的新项目上。
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.
我还没有测试过MOSS或SP2013。
#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
回收站中的项目具有DeletedDate,可以在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:
检查SPItemEventProperties.ListItemId属性的值:
- 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.
如果是0,那么它是一个新项目;
如果它不为0,则它是从回收站还原的项目。
#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.
从我使用SP2010的实验中,它看起来像properties.AfterProperties在项目来自回收站时为空,而它完全填充在实际的新项目上。
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.
我还没有测试过MOSS或SP2013。
#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
回收站中的项目具有DeletedDate,可以在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:
检查SPItemEventProperties.ListItemId属性的值:
- 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.
如果是0,那么它是一个新项目;
如果它不为0,则它是从回收站还原的项目。