EWS FindItems OrderBy - Sort by EmailMessageSchema.From Incorrect Order

你。 提交于 2019-12-07 06:24:24

问题


I am calling the EWS FindItems() method with an OrderBy on my View. The results are returned in the correct order if I use various ItemSchema.* values (ex. ItemSchema.DisplayTo, ItemSchema.Importance, ItemSchema.Subject).

But if I want the results sorted by EmailMessageSchema.From as the results are in an odd order that I can not understand and is not acceptable to my users.

Sorts Correctly: ItemSchema.Subject

ItemView view = new ItemView(20, 0, OffsetBasePoint.Beginning);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
view.OrderBy.Add(ItemSchema.Subject, SortDirection.Ascending);  
var findResults = service.FindItems(new FolderId(emails.CompositeUniqueFolderId), view);

Sorts Incorrectly: EmailMessageSchema.From

ItemView view = new ItemView(20, 0, OffsetBasePoint.Beginning);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
view.OrderBy.Add(EmailMessageSchema.From, SortDirection.Ascending);  
var findResults = service.FindItems(new FolderId(emails.CompositeUniqueFolderId), view);

Odd 'From' Order:

  1. MXX QA Team
  2. Shahzad Iqbal
  3. Kim Stevens
  4. Vikram Keswani
  5. Ulrich Patzer
  6. Shahzad Iqbal
  7. Shahzad Iqbal

If I sort by Descending the entries reverse in order. Emails #6 and #7 have a different SMPT address from #2. The pattern is not clear when looking at the SMTP addresses. The results do seem to be grouped by Address.MailboxType. That is the only slight pattern I can see.

How can I get the FindItems() results to sort correctly by EmailMessageSchema.From?


回答1:


The From and Sender properties are complex properties (eg contains more then one property). You would better just using the Extended property for what you want to Order the result on eg if you want to order the results based on the Sender Name use the pidtagSenderName property eg

        ExtendedPropertyDefinition Pr_Sender_Name = new ExtendedPropertyDefinition(0x0C1A, MapiPropertyType.String);
        ItemView view = new ItemView(20, 0, OffsetBasePoint.Beginning);
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
        view.PropertySet.Add(Pr_Sender_Name);
        view.OrderBy.Add(Pr_Sender_Name, SortDirection.Ascending);

Cheers Glen



来源:https://stackoverflow.com/questions/29266090/ews-finditems-orderby-sort-by-emailmessageschema-from-incorrect-order

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