Monday, March 14, 2011

Delete All Items, including Folders, from SharePoint List Programmatically and Efficiently

From this post by Praveen Modi.

/// Purges items and folders from a list
/// Define WSSV3 to remove list folders

/// The SPList you want to
/// purge items from
private static void PurgeList(SPList list)
Console.WriteLine("Purging list: " + list.Title);
Console.WriteLine("Base Type: " + list.BaseType.ToString());

// ===========================================================
// list.ItemCount returns a count that includes all items
// "AND" folders.
// You can't use list.Items.DeleteItemById() to remove a
// folder
// ===========================================================
System.Collections.Hashtable hItems =
new System.Collections.Hashtable(list.ItemCount);

// ===========================================================
// SPList.Items returns all list items in the entire list
// regardless of folder containment
// Note, just because list.ItemCount includes folders,
// list.Items does not.
// ===========================================================
foreach (SPListItem item in list.Items)

// Remove the list items
foreach (int ID in hItems.Keys)
// Clear the hashtable
// ===========================================================
// SPList.Folders returns all folder items in the entire list
// regardless of parent folder containment
// ===========================================================
foreach (SPListItem item in list.Folders)

// Remove the folder items
foreach (int ID in hItems.Keys)

Friday, March 11, 2011

Expiration Policy Timer job does not seem to run

Copied from this post:


The policy is run once a day, however fortunately you can start it manually. Using Central Admin->Operations->Information Management Policy Configuration, I clicked on the Expiration policy link. Then within there clicked "Process Expired Items Now". Looked at the Timer Job Status (Central Admin->Operations->Timer Job Status) and there was no reference of the Expiration Policy.

Looked within Timer Job Definitions (just under the Timer Job Status link) and a timer job had been created called "Expiration Policy (manually initiated)" but it had never been run. Actually neither had the daily "Expiration Policy". I went back to the Information Management Policy Configuration and into the Expiration policy. The "Process Expired Items Now" button was greyed out, to clear this I ended up deleting the "Expiration Policy (manual initiated)" timer job. This enabled the "Process Expired Items Now" button... however nothing.

Other things that I tried included stsadm -o execadmsvcjobs - though nanda.

Then I thought about the fact that the job had never been run and I found this article

Following the instructions sorted the problem...