Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EWS FindItems OrderBy - Sort by EmailMessageSchema.From Incorrect Order

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?

like image 275
Kim Stevens Avatar asked Mar 25 '15 20:03

Kim Stevens


1 Answers

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

like image 168
Glen Scales Avatar answered Oct 21 '22 22:10

Glen Scales