Sorting emails by subject in C# using MAPI on Outlook 2013
I'm trying to sort the email items in a folder by subject using C# and MAPI on Outlook 2013, but the Folder.Items.Sort("Subject",False)
command doesn't seem to work. The code I'm using is as follows:
NameSpace outlookNamespace = outlookApp.GetNamespace("MAPI");
outlookNamespace.Logon();
MAPIFolder OLAccount = outlookNamespace.Folders[sAccountName];
MAPIFolder OLFolder = OLAccount.Folders[sFolderName];
OLFolder.Items.Sort("Subject",false);
I've tried accessing each supposedly sorted mail item using a for
loop and a foreach
loop, but the order remains unchanged. There are no errors being returned. The records are returned in the following order:
Fw: 56-3-61
Fw: 57-8-9
Fw: 57-7-23.1C
Fw: 57-4-92
Fw: 57-4-55
Fw: 57-4-41.1E
Fw: 57-3-80.2
Fw: 57-8-38.7
I've included an image of the sought order.
Do you have any thoughts on how I might be able to achieve the desired sorting order? Thank you.