locked
Is it possible to clear the calendar using the EWS Managed API? RRS feed

  • Question

  • I tried the following to clear my outlook calendar and got an error saying: "Emptying the calendar folder or search folder isn't permitted."

            WellKnownFolderName c = WellKnownFolderName.Calendar;
            FolderId cId = new FolderId(c);
            try {
            Folder cal = Folder.bind(exService, cId);  // exService is of type ExchangeService
            cal.empty(DeleteMode.SoftDelete, false);
            }
            }
            catch(Exception ex) {
                System.out.println(ex.getMessage());
            }

     

    Sunday, January 15, 2012 2:27 AM

All replies

  • This is an Outlook programming forum, http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads
    is an Exchange development forum that takes EWS questions. The people there would be a lot more familiar with using EWS.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "PythonCoder5" <=?utf-8?B?UHl0aG9uQ29kZXI1?=> wrote in message news:ae80f17f-7025-42ad-9819-238d65f49303...

    I tried the following to clear my outlook calendar and got an error saying: "Emptying the calendar folder or search folder isn't permitted."

            WellKnownFolderName c = WellKnownFolderName.Calendar;
            FolderId cId = new FolderId(c);
            try {
            Folder cal = Folder.bind(exService, cId);  // exService is of type ExchangeService
            cal.empty(DeleteMode.SoftDelete, false);
            }
            }
            catch(Exception ex) {
                System.out.println(ex.getMessage());
            }

     


    Ken Slovak MVP - Outlook
    Monday, January 16, 2012 6:33 PM
  • As the error indicates using the Empty method isn't not supported on calendar folders so an alternative is to select the items you want to delete and then use a Batch delete eg

                ItemView iv = new ItemView(1000);
                FindItemsResults<Item> fiResults = null;
                do
                {
                    fiResults = service.FindItems(WellKnownFolderName.Calendar, iv);
                    List<ItemId> idItemIds = new List<ItemId>();
                    foreach (Item itItem in fiResults.Items) {
                        if (itItem is Appointment) {
                            idItemIds.Add(itItem.Id);
                        }
                    }
                    service.DeleteItems(idItemIds, DeleteMode.SoftDelete, SendCancellationsMode.SendToNone, AffectedTaskOccurrence.AllOccurrences); 
                    iv.Offset += fiResults.Items.Count;
                } while (fiResults.MoreAvailable == true);
    

    Cheers
    Glen

    Tuesday, January 17, 2012 2:21 AM