Jaa


How to delete SPRecycleBin items?

    1: SPSite spSite = new SPSite("https://nishand:100/sites/InternetSite/");
    2: SPRecycleBinItemCollection collection = spSite.RecycleBin; 
    3:  
    4: for (int x = 0; x < collection.Count ; x++) 
    5: {           
    6:               collection[x].Delete(); x = x-1;                               
    7: }
    8:  

The above code works only for the items deleted by the user who runs the application/current user.
Any attempt to delete a file deleted by other user from the recycle bin file will result in an exception "Operation is not valid due to the current state of the object."

We do have an overridden Delete() function, that helps to delete all RecycleBin items.

SPRecycleBinItemCollection.Delete(Guid [] guids)

Hope this works for you!

Comments

  • Anonymous
    June 08, 2008
    Un besoin très classique pour tout responsable de ferme SharePoint 2007 est la gestion des corbeilles.