Click here to Skip to main content
14,695,406 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create VSTO addin to an Outlook Application
and I try to enumerate subfolders in shared exchange mailbox (this is not my primary mailbox, i have only full access rights to that mailbox).

Unfortunately, my code give me empty collection

using System;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace ManageSharedMailbox {
    public partial class MSMAddIn {
        private void ThisAddIn_Startup(object sender, System.EventArgs e){
            PrepareRibbons();            
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e){}

        private void InternalStartup(){
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        private void PrepareRibbons() {
            const string PomijanePrefixy = "!@#$%^&*()_+=[]{};':\",./<>?|\\`~ ";
            const string PomijaneNazwy = "|archiwum|itemprocsearch|folder nadrzędny folderów osobistych|folder główny wyszukiwania|ipm_common_views|foldery wyszukiwania|freebusy data|";

            foreach (Outlook.Folder folder in Application.Session.Folders) {

                if (null == folder.Store) continue;

                if (!folder.Store.IsOpen) continue;

                Outlook.OlExchangeStoreType storetype = folder.Store.ExchangeStoreType;
				
                if (storetype == Outlook.OlExchangeStoreType.olExchangePublicFolder) continue;

                if (storetype != Outlook.OlExchangeStoreType.olExchangeMailbox) continue;

                //  I skip connected mailboxes without "SHARED" text in name 
                if (!folder.Name.ToLower().Contains("shared")) continue;

                Outlook.MAPIFolder ofInbox = folder.Store.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                if (null == ofInbox) continue;

                foreach (Outlook.Folder folderQuery in folder.Folders) {                    
                    if (folderQuery.DefaultItemType != Outlook.OlItemType.olMailItem) continue;

                    //  I parse only INBOX folder 
                    if (folderQuery.EntryID != ofInbox.EntryID) continue;
                    
                    foreach (var item in folderQuery.Items) {
                        //  Works, I can iterate through emails (not folders!) in this folder 
                    }

                    foreach (Outlook.Folder folderEntries in folderQuery.Folders) {
                        //  This collection is always empty, 
                        // regardless of how many subfolders 
                        // I have in the Inbox folder selected shared mailbox
                        // How to fill that collection ? 
                        // or get list of these folders ?
                    }               
                    break;                                        
                }
                if (null != ofInbox) Marshal.ReleaseComObject(ofInbox);
            }
        }
	}
}




This code works ok, if I parse my primary exchange OR connected .pst files.

What I have tried:

I try to get via Outlook.Explored object, but without success.

I also changed "CacheOthersMail" value to 1 at HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\14.0\outlook\Cached Mode\ key
Posted
Updated 29-Mar-16 3:53am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900