本文介绍了使用EWS的PR_SEARCH_KEY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 EWS 为某些邮件提取 PR_SEARCH_KEY .我之前是使用Outlook API来做的.但是我想用EWS重新编写完整的代码,因为它功能强大.

旧代码:

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;
        }

新代码:

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

但是我无法获取它的String值.

解决方案

它是一个Binary属性,因此,如果要获得与OOM中相同的十六进制字符串,只需使用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);
            }

        }

欢呼格伦

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.

解决方案

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);
            }

        }

CheersGlen

这篇关于使用EWS的PR_SEARCH_KEY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 11:18