Dumping Dated SharePoint Recycle Bins [Fix]
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;
-
}
-
}
-
}
-
}
1 Comment »
RSS feed for comments on this post. TrackBack URL





















Articles & Research
SharePoint Architecture
Personal/Off-Topic
Latest Free SharePoint Software
SecureCenter For SharePoint
SharePoint Security Assurance Program™
Free Online SharePoint Security Tools
Online SharePoint Security Health Assessment
Article Or Research Filed Under 
[...] Dumping Dated SharePoint Recycle Bins [Fix] [...]
Pingback by Links (9/25/2008) « Steve Pietrek - Everything SharePoint — September 25, 2008 @ 5:40 pm