Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

There is a SharePoint List from which many records have been deleted using CAML. The records are available in the Recycle Bin.

Is there an way to recover the records using scripting/CAML etc ? Since it's not efficient to recover the records manually.

Regards, André

share|improve this question
2  
found something on stackoverflow.com/questions/4095884/… –  Dre May 23 '11 at 7:35
add comment

1 Answer 1

up vote 1 down vote accepted

This code will restore all the items deleted from the specified list:

string listUrl = "web/relative/list/url"; // without leading slash!
var toRestore = new List<SPRecycleBinItem>();
foreach (SPRecycleBinItem recycleBinItem in web.RecycleBin)
{
    if (recycleBinItem.ItemType == SPRecycleBinItemType.ListItem
        && recycleBinItem.DirName.ToLowerInvariant() == listUrl.ToLowerInvariant())
    {
        toRestore.Add(recycleBinItem);
    }
}

foreach (var itemToRestore in toRestore)
{
    itemToRestore.Restore();
}

Note: this code will require elevated privilegies, if you want to allow ordinary portal users to use it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.