How to restore deleted appointment

旧时模样 提交于 2019-12-25 04:28:40

问题


How to restore deleted appointment using EWS 2.0? I think i could search for it in the WellKnownFolderName.RecoverableItemsDeletions folder. But all i have is ItemId. And sadly I cant use it in SearchFilter...

What is the best way?

my try:

    ItemView view = new ItemView(10);

SearchFilter searchFilter = new SearchFilter.IsEqualTo(ItemSchema.Id, itemChange.ItemId);

var findResults = exchangeService.FindItems(WellKnownFolderName.RecoverableItemsDeletions, searchFilter, view);

List<ItemId> ids = null;
foreach (var findResult in findResults)
{
    Debug.WriteLine(findResult.Id.ToString());
    ids.Add(findResult.Id);
}
exchangeService.MoveItems(ids, WellKnownFolderName.Calendar);

an error occurs:

{"Values of type 'ItemId' can't be used as comparison values in search filters."}


回答1:


Set your WellKnownFolderName to DeletedItems when you are searching for the appointments. And you should set up your search filter to only return appointments since the DeletedItems folder can hold more than just the appointments you are looking for. Here is an example that should work for you.

ItemView view = new ItemView(10);
// Only look for appointments
SearchFilter searchFilter = new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "IPM.Appointment");
// Look for items in the DeletedItems folder
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.DeletedItems, searchFilter, view);
// Move each of the deleted items back to the calendar
List<ItemId> ItemsToMove = new List<ItemId>();
foreach (Item item in results)
{
    ItemsToMove.Add(item.Id);
}
service.MoveItems(ItemsToMove, WellKnownFolderName.Calendar);


来源:https://stackoverflow.com/questions/22379041/how-to-restore-deleted-appointment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!