我设计了一个自定义保留策略,通过该策略,我的文档库中的项目会在一定天数后被硬删除。
从文档库中删除这些项目后,我必须更新另一个列表,因为这些项目的状态为已归档。
但是项目删除事件接收器不会被触发。
事件接收者代码
public override void ItemDeleting(SPItemEventProperties properties)
{
try
{
base.ItemDeleting(properties);
SPWeb oWeb = properties.Web;
SPListItem spLI = properties.ListItem;
SPList oList = oWeb.GetList("mylist");
string fileName = spLI.Name;
string userID = string.Empty;
if (oList != null)
{
SPQuery query = new SPQuery();
query.Query = "<Where><And><Eq><FieldRef Name=\"ReportName\" /><Value Type=\"Text\">" + fileName + "</Value></Eq><Eq><FieldRef Name=\"ReportStatus\" /><Value Type=\"Text\">COMPLETED</Value></Eq></And></Where>";
query.ViewFields = "<FieldRef Name=\"UserID\" /><FieldRef Name=\"ReportStatus\" /><FieldRef Name=\"ReportName\" />";
query.RowLimit = Constants.CAML_QUERY_ROW_LIMIT;
query.ViewAttributes = Constants.CAML_QUERY_VIEW_ATTRIBUTES_ALL;
SPListItemCollection allfiles = reportInfoList.GetItems(query);
if (allfiles != null)
{
if (allfiles.Count > 0)
{
foreach (SPListItem spReportInfoItem in allfiles)
{
userID = spReportInfoItem["UserID"].ToString();
spReportInfoItem["Status] = "Archived";
spReportInfoItem.SystemUpdate();
}
}
}
}
}
catch (Exception expException)
{
throw expException;
}
}