PR_SEARCH_KEY using EWS

送分小仙女□ 提交于 2019-12-02 15:16:02

问题


I need to extract PR_SEARCH_KEY for some mails using EWS. I was doing it using Outlook API earlier. But I want to re-write complete code in EWS as it is much powerful.

Old code:

private String GetLnksForMailBoxMails(Outlook.MailItem mail)
        {
            const string PR_SEARCH_KEY =
                "http://schemas.microsoft.com/mapi/proptag/0x300B0102";

            Outlook.PropertyAccessor pa = mail.PropertyAccessor;
            String searchKey = pa.BinaryToString(pa.GetProperty(PR_SEARCH_KEY));
            //    Console.WriteLine("Here is lnks for normal mail box:{0} ", searchKey);
            return searchKey;
        }

New Code:

ExtendedPropertyDefinition eDef = new ExtendedPropertyDefinition(0x300B, MapiPropertyType.Binary);
                PropertySet prop = BasePropertySet.IdOnly;
                prop.Add(eDef);
                ItemView ivItemView = new ItemView(5000);
                ivItemView.PropertySet = prop;

But I am not able to get String value for it.


回答1:


Its a Binary property so what you will get back is a Binary Array if you want to get the same Hex String as in the OOM just use something ilke

        ExtendedPropertyDefinition eDef = new ExtendedPropertyDefinition(0x300B, MapiPropertyType.Binary);
        PropertySet prop = BasePropertySet.IdOnly;
        prop.Add(eDef);
        ItemView ivItemView = new ItemView(1000);
        ivItemView.PropertySet = prop;
        FindItemsResults<Item> fiResults = Inbox.FindItems(ivItemView);
        foreach (Item itItem in fiResults) {
            Byte[] PropVal;
            String HexSearchKey;
            if (itItem.TryGetProperty(eDef, out PropVal)) {
                HexSearchKey = BitConverter.ToString(PropVal).Replace("-", "");
                Console.WriteLine(HexSearchKey);
            }

        }

Cheers Glen



来源:https://stackoverflow.com/questions/24818502/pr-search-key-using-ews

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