none
Delete data from recycle bin which has same source/origion using C# sharepoint RRS feed

  • Question

  • Hi,

    I am looking for some custom c# code which would be useful to delete the items which are coming from same origin/source.

    Can anyone suggest how to filter out items from SharePoint recycle bin and delete them. 

    I know deleting all items is possible but let me know some reference for some specific items.

    Regards:

    Sanjay

    Thursday, March 23, 2017 11:25 AM

All replies

  • Hi Sanjay,

    The following code snippet for your reference:

    using (SPSite site = new SPSite("http://sp13/sites/test1")) 
    {  
    
    	using (SPWeb web = site.OpenWeb()) 
    	{
    		var originalLocation = "sites/test1/Lists/CustomList12";
    		SPRecycleBinItemCollection rbItems =web.RecycleBin;
    		List<SPRecycleBinItem> listItems=new List<SPRecycleBinItem>();
    		foreach(SPRecycleBinItem rbItem in rbItems)
    		{
    			if (rbItem.DirName.Contains(originalLocation))
    			{
    				listItems.Add(rbItem);                             
    			}
    		}
    		foreach(var item in listItems)
    		{
    			item.Delete();
    		}
    	} 
    } 

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Sunday, March 26, 2017 6:18 AM
    Moderator