How to purge the mailbox folder items in exchange server 2007 and 2010? RRS feed

  • Question

  • Hello Friends,

    Can anybody tell me if there is any way to purge any standard or custom mailbox folders in exchange server 2007 and 2010? How to do that?

    Thanks in advance.

    Thursday, July 28, 2011 7:24 PM

All replies

  • Depends what you really mean by purge ? When you delete an Item in Exchange you can do a Soft delete (meaning the item can be recovered) or Hard delete (no chance of recover) which on 2007 programatically would require that you enuerate each items within a folder you want to delete and then delete them for example if you where using EWS you would generally want to batch this operation eg are simple exmple of deleting all items in the Inbox using the Managed API

          Folder Inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
          ItemView ivItemView = new ItemView(1000);
          ivItemView.PropertySet = new PropertySet(BasePropertySet.IdOnly);
          List<List<ItemId>> DeleteBatches = new List<List<ItemId>>();
          FindItemsResults<Item> fiItems = null;
            fiItems = Inbox.FindItems(ivItemView);
            List<ItemId> dlDeletItems = new List<ItemId>();
            foreach (Item itItem in fiItems.Items) {
            ivItemView.Offset += fiItems.Items.Count;
          } while (fiItems.MoreAvailable == true);
          foreach(List<ItemId> dlBatch in DeleteBatches){
            service.DeleteItems(dlBatch, DeleteMode.HardDelete, SendCancellationsMode.SendToNone, AffectedTaskOccurrence.AllOccurrences);

    One 2010 SP1 things can be a little different if you using Single Item Recovery programmatically in EWS its a little easier to delete all the items form a folder using the Empty method which is outlined in . But you may find that actually purging the Item from the store because of Single Item Recovery is different.



    Friday, July 29, 2011 2:05 AM