Reputation: 311
I have designed a custom retention policy through which items of my document library gets hard deleted after a certain amount of days.
After these items are deleted from the document library, I have to update another list as these item status as archived.
But the item deleting event receiver doesn't get fired.
Event Reciever code
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;
}
}
Upvotes: 2
Views: 254
Reputation: 311
After a lot of google I figured out that a SystemUpdate() which does not fire events. And the retention policy deletes from the list is a SystemUpdate() hence my event receiver doesn't get fired. So I changed my code accordingly.
Upvotes: 1