Convert Outlook EntryID to EwsID Exchange Web Services

I found myself trying to find an email in Exchange the other day, based on the EntryID I could retrieve from the email in Outlook (Exchange account). I was using Exchange Web Services EWS to access the mailbox the email was stored in. In EWS you can retrieve an item by providing its ID

Dim item As Item = item.Bind(service, New ItemId(entryid))
 
Well quickly I found out that the EntryID of the email in Outlook was not what I wanted. After some reading I discovered the ConvertId function that converts ids from one format to another. The available formats are 
  • EntryId
  • EwsId
  • EwsLegacyId
  • HexEntryId
  • OwaId
  • StoreId  

So I went on to do the obvious, convert my ID from EntryId to EwsId. I wish!
Microsoft.Exchange.WebServices.Data.ServiceResponseException "The specified object was not found in the store." was what I got to my surprise!

What actually was wrong was that the EntryID was not in EntryId format but in HexEntryId format.

The code that gets the job done is the following:

        Dim originalID As New AlternateId()
        originalID.Format = IdFormat.HexEntryId
        originalID.Mailbox = "info@me.com"
        originalID.UniqueId = entryID 'EntryId retrieved from email in Outlook

        Dim altBase As AlternateIdBase = esb.ConvertId(originalID, IdFormat.EwsId)
        Dim convertedID As AlternateId = DirectCast(altBase, AlternateId)
        Dim strConvertedID As String = convertedID.UniqueId


 I hope this will save you some time ;-)

Comments

Popular posts from this blog

ASP.NET entity datasource control error - The metadata specified in the connection string could not be loaded. Consider rebuilding the web project to build assemblies that may contain metadata.The following error(s) occurred. The provider did not return a Provider Manifest instance.

Freeze panes in BO Webi report like Excel