Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EWS Managed API find items with ItemID

I am trying to find items from deleted items folder given the items unique id

ItemId id = new ItemId("zTK6edxaI9sb6AAAQKqWHAAA");
SearchFilter.IsEqualTo filter = new SearchFilter.IsEqualTo(ItemSchema.Id, id);
ItemView view = new ItemView(10);
view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.Subject);
FindItemsResults<Item> results = _ExchangeService.FindItems(WellKnownFolderName.DeletedItems, filter, view);
Console.WriteLine(results.TotalCount);

This code returns an exception saying:

Validation failed.
Parameter name: searchFilter

The same code works if I search for a message with Subject.

like image 975
nilobarp Avatar asked Dec 13 '13 15:12

nilobarp


People also ask

What is EWS Managed API?

Microsoft's Exchange Web Services (EWS) provides an Exchange email API that provides access to all of the data and functionality in Exchange mailboxes; it enables developers to parse email data, create email drafts, send emails, manage attachments, and organize an email inbox with folders.

Is EWS an API?

Exchange Web Services (EWS) is an application program interface (API) that allows programmers to access Microsoft Exchange items such as calendars, contacts and email.

What is EWS in email?

Exchange Web Services (EWS) is a cross-platform API that enables applications to access mailbox items such as email messages, meetings, and contacts from Exchange Online, Exchange Online as part of Office 365, or on-premises versions of Exchange starting with Exchange Server 2007.


2 Answers

You don't need to use FindItems if you already know the ItemId

EmailMessage email = EmailMessage.Bind(service, new ItemId(StringItemId));
like image 106
Abhi Avatar answered Oct 17 '22 01:10

Abhi


You cannot search on a ComplexProperty such as the ItemId. I'm assuming that Item.Bind won't work due to the item being moved, which changed the ItemId?

If that's the case, then you'll need to use a SearchFilter on another property. If these are Items that you created via EWS, you could attach a unique Extended Property to each and use that if you need to search for one.

like image 32
user1017413 Avatar answered Oct 17 '22 01:10

user1017413