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

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

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.