For whatever rationale, typed iterations to dump particular SPRecycleBinItem objects out of the SharePoint recycle bin don’t work due to a problem with the proc_DeleteRecycleBinItem stored procedure. But it seems to be indeterminate and I can’t locate any sort of thresholds.
So, for some reason:
-
public static void NonWorkingRecycleBinDump(string url)
-
{
-
{
-
using (SPWeb web = site.OpenWeb())
-
{
-
SPRecycleBinItemCollection coll = site.RecycleBin;
-
foreach (SPRecycleBinItem item in coll)
-
{
-
item.Delete();
-
}
-
}
-
}
-
}
will not work in some environments, with certain items. I cushion the claim with the “some” because my testing has been limited to my VM, some production stuff, and the SharePoint support engineer’s VM I am talking to. It's nonetheless a frustrating problem to run into.
It should be noted that this apparently isn’t the case however when using the SPWeb.RecycleBin.DeleteAll() if you are doing a complete dump, as detailed here:
The final solution to the aforementioned problem is documented here:
http://blogs.msdn.com/nishand/archive/2008/06/07/how-to-delete-sprecyclebin-items.aspx
However, this doesn’t take into account hydrating specific DateTime objects. In order to introduce this functionality, we just have to modify this code slightly. In this case, through the use of the DateTime.Compare method, we can remove certain logs based on their DeletedDate property.
-
public static void WorkingRecycleBinDump(string url)
-
{
-
{
-
using (SPWeb web = site.OpenWeb())
-
{
-
SPRecycleBinItemCollection coll = web.RecycleBin;
-
for (int x = 0; x <coll.Count; x++)
-
{
-
DateTime deletedTime = coll[x].DeletedDate;
-
DateTime selectedTime = [your DateTimeObject];
-
if (DateTime.Compare(selectedTime, deletedTime)> 0)
-
{
-
ids[0] = coll[x].ID;
-
coll.Delete(ids);
-
}
-
x = x - 1;
-
}
-
}
-
}
-
}






![Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a Del.icio.us Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a Del.icio.us](http://www.sharepointsecurity.com/blog/wp-content/plugins/social-bookmarking-reloaded/delicious.png)
![Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a digg Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a digg](http://www.sharepointsecurity.com/blog/wp-content/plugins/social-bookmarking-reloaded/digg.png)
![Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a Technorati Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a Technorati](http://www.sharepointsecurity.com/blog/wp-content/plugins/social-bookmarking-reloaded/technorati.png)
![Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a Bloglines Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a Bloglines](http://www.sharepointsecurity.com/blog/wp-content/plugins/social-bookmarking-reloaded/bloglines.png)
![Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a Netscape Add 'Dumping Dated SharePoint Recycle Bins [Fix]' a Netscape](http://www.sharepointsecurity.com/blog/wp-content/plugins/social-bookmarking-reloaded/netscape.gif)
September 25th, 2008 at 5:40 pm
[...] Dumping Dated SharePoint Recycle Bins [Fix] [...]