question

RZAGmbHMarioAbleidinger-2667 avatar image
0 Votes"
RZAGmbHMarioAbleidinger-2667 asked RZAGmbHMarioAbleidinger-2667 commented

Get folders in same order as in Outlook via C# with Microsoft.Office.Interop.Outlook

How do I get the folders in the same order as they appear in Outlook?
I am using this code to get the folders:

 static void Main(string[] args)
 {
    
     var outlookApp = new Microsoft.Office.Interop.Outlook.Application();
     var ns = outlookApp.GetNamespace("MAPI");
     var folder = ns.Folders[2];
     Console.WriteLine($"+++ {folder.Name} +++");
     foreach (Microsoft.Office.Interop.Outlook.Folder subFolder in folder.Folders)
     {
         Console.WriteLine(subFolder.Name);
     }
 }

Then I get this list of results:

80903-5.jpg

However, in Outlook they are displayed in this order:

80904-6.jpg

dotnet-csharp
5.jpg (171.6 KiB)
6.jpg (91.3 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@RZAGmbHMarioAbleidinger-2667
For the security of your personal data, please be careful not to include the real phone number, email address and other private information when posting pictures or codes.

0 Votes 0 ·

1 Answer

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered RZAGmbHMarioAbleidinger-2667 commented

In Microsoft.Office.Interop.Outlook, these folders are sorted by StoreID by default.

But in the Outlook application, it seems that we can only manually adjust the order or sort by the first letter of the name, and when sorting by the first letter, Inbox, Drafts, Sent Items, Deleted Items do not participate in the sorting, and are always in the top four.

I tried to find a way to get the folder sorting in the current outlook application in the code, but unfortunately it seems impossible to do it. I will continue to investigate and if there are new discoveries, I will tell you immediately.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your answer.

0 Votes 0 ·