3

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é

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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