Sorting emails by subject in C# using MAPI on Outlook 2013

Wart Pendragon 0 Reputation points
2024-04-17T18:08:24.9633333+00:00

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.

User's image

Do you have any thoughts on how I might be able to achieve the desired sorting order? Thank you.

Microsoft 365 and Office | Development | Other
Outlook | Windows | Classic Outlook for Windows | For business
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.