SharePoint: Folder cannot be deleted because it contains items which are either on hold or declared as records

While working on a SharePoint 2010 Records Management project, I tried to delete a folder inside Record Library and encountered the following error.
Folder cannot be deleted because it contains items which are either on hold or declared as records


The error message is self explanatory. It turned out that the folder contained a document which was declared as a record. In order to delete the folder, the document needed to be undeclared as a record. This can be done by clicking on Compliance Details and then "Undeclare Record" in Record Status section of the popup as shown:

Now we can delete the folder which contained this document. 
Following piece of code can be used to undeclare items as records.

SPList list = web.Lists["Record Library"];
foreach (SPListItem item in list.Items)
{
    if (Records.IsRecord(item))
        Records.UndeclareItemAsRecord(item);
}

Records class can be found in Microsoft.Office.RecordsManagement.RecordsRepository namespace which is present in Microsoft.Office.Policy.dll
profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+