1

I'm trying to programmatically restore documents from the sharepoint recycle bin. In an external database, the document IDs are stored, and I'm looking to restore item(s) according to some document Id(s).

I'm fairly certain this information must be kept, as the document IDs are preserved whenever I manually delete/restore them.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite mySite = new SPSite("http://mysharepoint/sites/mysite")){
        SPRecycleBinQuery query = new SPRecycleBinQuery
        {
            RowLimit = 200, 
            ItemState = SPRecycleBinItemState.FirstStageRecycleBin,
            OrderBy = SPRecycleBinOrderBy.DeletedDate,
            ItemCollectionPosition = SPRecycleBinItemCollectionPosition.FirstPage
        };
        SPRecycleBinItemCollection coll = mySite.GetRecycleBinItems(query);

        foreach(SPRecycleBinItem item in coll )
        {
            ???
        }
});

The above code snippet works fine (assuming max of 200 items for the moment) for getting all deleted documents. The closest to an ID property that an SPRecycleBinItem item has is GUID. Is it possible to determine the doc ID from that?

1

I do not see a property on SPRecycleBinItem for the Document ID. You could put a breakpoint in your code and step into it. Maybe there is a non-documented property that you can drill into and find this value.

The documentation for SPRecycleBinItem.ID states that this is the transaction ID of the delete transaction. It looks like this value is stored in the content database in dbo.AllDocs, but I can not find where it is exposed in the object model. Since, you're not supposed to query the database directly, I don't see how you could use this ID to get the deleted document.

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.