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.

C#
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.
10,259 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,497 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,895 questions
0 comments No comments
{count} votes