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:
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With