Deleting items to recycle bin in Sitecore

There are several ways to delete an item in Sitecore programatically. The simplest is to use the item.Delete() function:

Item item = Database.GetDatabase("master").GetItem("/sitecore/content/home/myitem");

This, however will delete the item entirely, not move it to the recycle bin. Instead you should use the item.Recycle():

Item item = Database.GetDatabase("master").GetItem("/sitecore/content/home/myitem");

You could also check to see if the Recycle Bin is enabled (can be disabled in the web.config using the RecycleBinActive setting):

Item item = Database.GetDatabase("master").GetItem("/sitecore/content/home/myitem");
if (Sitecore.Configuration.Settings.RecycleBinActive)

If you are creating your own command, or is using the shell somehow, you could also activate the uiDeleteItems pipeline. Activating the pipeline will prompt the user for each item to be deleted:

public void Delete(Item[] items)
  Assert.ArgumentNotNull(items, "items");
  Sitecore.Shell.Framework.Items.Delete(items, string.Empty);

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, Sitecore 6 and tagged , , , . Bookmark the permalink.

9 Responses to Deleting items to recycle bin in Sitecore

  1. Adam Weber says:

    Hi Brian,

    I just wanted to point out that calling item.Recycle() will first check to ensure that the recycle bin is active and if not, then it will call item.Delete().

    We’ve therefore just been making it standard practice to call item.Recycle() in our code and let it take care of our logic.

    Great post!


  2. briancaos says:

    Yes I can see that it’s true.
    Also, Recycling is the same as archiving, as the Recycle() function uses the ArchiveManager, archiving the item to the recyclebin.

  3. Mortaza says:

    if you want to Archive an item:

    Database contentDatabase = Context.ContentDatabase;
    ArchiveManager.GetArchive(“archive”, contentDatabase).ArchiveItem(item);

    If you want to get the items in Archive table (ppl refer to Archive Database well it’s true if you use Sitecore 5 but in 6, it’s just a table)

    Sitecore.Data.Archiving.Archive archive = ArchiveManager.GetArchive(“archive”, Sitecore.Context.ContentDatabase);

    IEnumerable archiveEntryList = archive.GetEntries(1, archive.GetEntryCount());

    foreach(ArchiveEntry archiveEntry in archiveEntryList)
    // here you do your logic :)
    string name = archiveEntry.Name;
    ID id = archiveEntry.ItemId;
    Item item = Sitecore.Context.Database.GetItem(id);

  4. Patty Williams says:


    What if I want to archive an item to the archive? When I try the code below, nothing happens:

    Archive archive = ArchiveManager.GetArchive(“archive”, masterDB);

  5. Patty Williams says:

    Sorry, didn’t include the line for masterDB in my previous post:

    Database masterDB = Sitecore.Data.Database.GetDatabase(“master”);

  6. Mrunal says:

    Hi Adam,

    I believe this Delete and Recycle should keep different because we have one requirement where Team Lead can have access to Recycle Button(Custom Made) and Delete button, where are other users have access to only Delete button.

    Thus it give flexibility to add different command for different scenarios.


  7. Ehsan says:

    Can someone please tell me the difference between Sitecore Archiving and Sitecore Recycling?

  8. briancaos says:

    The recycle bin is just a standard archive so there is no difference at all.

  9. Hi Adam,

    How to create pipeline for add, remove and move the sitecore items?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s