none
EWS: How to get last item in conversation thread? RRS feed

  • Question

  • Hi,

    I need to reply to the latest email item in conversation thread. I have ConversationId stored as a string and ConversationIndex stored as a Base64String. I try to search by ConversationID, but it finds nothing. What I'm doing wrong?

    I'm using Exchange 2010 SP2 and EWS 2.1.

       

    ExtendedPropertyDefinition ConversationIdProperty = new ExtendedPropertyDefinition(0x3013, MapiPropertyType.Binary);
    ExtendedPropertyDefinition ConversationIndexProperty = new ExtendedPropertyDefinition(0x0071, MapiPropertyType.Binary);

    ConversationIdci = new ConversationId(conversationIdString);
    SearchFiltersf = new SearchFilter.IsEqualTo(ConversationIdProperty, ci.UniqueId);
    var view = new ItemView(512)
                        {
    PropertySet = new PropertySet(BasePropertySet.FirstClassProperties,
    ConversationIdProperty, ConversationIndexProperty)
                        };              

    varitemsInbox = es.FindItems(WellKnownFolderName.Inbox, sf, view);

    I also tried the FindConversation of ExchangeService, but get "FindConversation is only valid for Exchange Server version Exchange 2013 or later." error, although according to MSDN it is supported in 2010.

    Please help!

                                                                                                                                   
    Wednesday, March 19, 2014 4:37 AM

Answers

  • Sorry,

    my test has been done against an Exchange 2013...

    ConversationId cid;
    ExtendedPropertyDefinition ConversationIdProperty = new ExtendedPropertyDefinition(0x3013, MapiPropertyType.Binary);
    
    byte[] cidBinary = Convert.FromBase64String(cid.UniqueId);
    byte[] cidGuid = new byte[16];
    //it seems that the value required are the 16 last bytes
    Array.Copy(cidBinary, 43, cidGuid, 0, 16);
    string toSearch = Convert.ToBase64String(cidGuid);
    
    SearchFilter conversation = new SearchFilter.IsEqualTo(ConversationIdProperty, toSearch);

    Regards,


    Désiré GOVIN Refresh IT Solutions

    • Marked as answer by asft Wednesday, March 19, 2014 5:11 PM
    Wednesday, March 19, 2014 4:21 PM

All replies

  • Hi,

    replace ConversationIdProperty with EmailMessageSchema.ConversationId .

    Regards,


    Désiré GOVIN Refresh IT Solutions

    Wednesday, March 19, 2014 8:22 AM
  • Thank you for the reply.

    I already tried this option and I get: "The property can not be used with this type of restriction." exception.

    Here is my code:

        try
                    {
                        var view = new ItemView(512)
                        {
                            PropertySet = new PropertySet(BasePropertySet.FirstClassProperties,
                                EmailMessageSchema.ConversationId)
                        };

                        var bb = es.FindItems(WellKnownFolderName.SentItems, view);

                        var cId = bb.Items[0].ConversationId;

                        SearchFilter sf = new SearchFilter.IsEqualTo(EmailMessageSchema.ConversationId, cId.UniqueId);
                        var itemsSent = es.FindItems(WellKnownFolderName.SentItems, sf, view);               
                    }
                    catch (Exception ex)
                    {
                        string s = "";
                    }

    Wednesday, March 19, 2014 3:05 PM
  • Sorry,

    my test has been done against an Exchange 2013...

    ConversationId cid;
    ExtendedPropertyDefinition ConversationIdProperty = new ExtendedPropertyDefinition(0x3013, MapiPropertyType.Binary);
    
    byte[] cidBinary = Convert.FromBase64String(cid.UniqueId);
    byte[] cidGuid = new byte[16];
    //it seems that the value required are the 16 last bytes
    Array.Copy(cidBinary, 43, cidGuid, 0, 16);
    string toSearch = Convert.ToBase64String(cidGuid);
    
    SearchFilter conversation = new SearchFilter.IsEqualTo(ConversationIdProperty, toSearch);

    Regards,


    Désiré GOVIN Refresh IT Solutions

    • Marked as answer by asft Wednesday, March 19, 2014 5:11 PM
    Wednesday, March 19, 2014 4:21 PM
  • Thank you! Your solution works.
    Wednesday, March 19, 2014 5:11 PM