问题
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