How to programmatically select a folder to view in Outlook 2010?

c#, outlook, outlook-2010, vsto

Solution

This should work for you...

Get access to your `Application` object (or from the main add-in class). And then

this.Application.ActiveExplorer().CurrentFolder = folder;  

i.e. you can use `CurrentFolder` of the `ActiveExplorer`

Of course, always make sure to properly release your COM objects (the ones that need releasing) - and you should never do it like I did here (for simplicity) - i.e. chaining properties like that. Save each (property) into a variable, and release via `Marshal.ReleaseComObject` on your way out.

Problem

I am programmatically creating a search folder via Search.Save method. After I save the search (it creates a new folder in the Search Folders directory), I would like to set to focus on this newly created folder such that the view changes to this folder. This is the code I have thus far.... ``` searchFolders = inboxFolder.Store.GetSearchFolders(); foreach (Outlook.Folder folder in searchFolders) { if (folder.Name == "Expiring Retention Policy Mail") { folder.ShowItemCount = Microsoft.Office.Interop.Outlook.OlShowItemCount.olShowTotalItemCount; //folder.SetCustomIcon(new Bitmap(32, 32)); folder.Display(); } } ``` When I do folder.Display() it opens up an entirely new inspector window... I don't want this to happen, I simply want to select it (like via set focus?) and have it viewed in the same inspector window it exists in. Does anybody know how to do this? Thank you.

Original source