Using C#, MAPI on Outlook 2013 email system. Trying to sort the emails in the folder but Folder.Items.Sort("Subject",False) does not work
Using C#, MAPI trying to sort a mail folder by Subject. The output from the below code shows that the Outlook Folder Items are not sorted by Subject. The order is not changed with or without a call to Items.Sort.
NameSpace outlookNamespace = outlookApp.GetNamespace("MAPI");
outlookNamespace.Logon();
MAPIFolder OLAccount = outlookNamespace.Folders[sAccountName];
MAPIFolder OLFolder = OLAccount.Folders[sFolderName];
OLFolder.Items.Sort("Subject",false);
// Access each supposedly sorted mail item. Makes no difference if the sort order is true or false
for(int iMailCount = 1; iMailCount < OLFolder.Items.Count; iMailCount +=1)
{
Console.WriteLine($"{iMailCount} - {OLFolder.Items[iMailCount].Subject}");
}
//The mail items are not sorted
//Tried this with same result - not sorted
foreach (MailItem eMail in OLFolder.Items)
{
Console.Write($". {eMail.Subject}")
}
Any thoughts?
Thanks