How get the corresponding account from an selected addressbook folder

Add-in Express™ Support Service
That's what is more important than anything else

How get the corresponding account from an selected addressbook folder
account the selected Folder are correspond 
Joachim Weber


Guest


Hi,

for my application I want to know the corresponding account to an selected folder. For example: There are tow mail accounts the first "1@test.com" and the second "2@other.com". Each of the accounts contain their own addressbook. If the user have selected an folder I want to know, the name of the corresponding account. I have used the "ExplorerFolderSwitch" Event to get the information, but without success.
See my code:

        private void adxOutlookAppEvents1_ExplorerFolderSwitch(object sender, object explorer)
        {
            Outlook.Explorer exp = (Outlook.Explorer)explorer;
            Outlook.Folder curFold = (Outlook.Folder)exp.CurrentFolder;
            Outlook.Account testAccount = exp.AccountSelector.SelectedAccount;

            MessageBox.Show("Account: " + testAccount.DisplayName);
            
        }


Do somebody know how I can get the corresponding account name?
Thanks for your answer.

Joachim
Posted 28 May, 2015 10:37:15 Top
Joachim Weber


Guest


Hello,

I have solved my problem, here is the code to get the corresponing account for an folder:

        //For example:
        MessageBox.Show("Account for the currentFolder: "+ this.GetAccountForFolder(curFold).DisplayName);

        public Outlook.Account GetAccountForFolder(Outlook.Folder oFolder)
        {   
            Outlook.Account oReturn = null;
            Outlook.Store oFolderStore = oFolder.Store;

            foreach (Outlook.Account oAccount in OutlookApp.Session.Accounts)
            {
                if (oAccount.DeliveryStore.StoreID == oFolderStore.StoreID)
                {
                    oReturn = oAccount;
                }
            }
            return oReturn;
        }


Enjoy it!

Joachim
Posted 29 May, 2015 01:51:13 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Thank you Joachim!

I'd use a for loop instead of foreach and release all COM objects. I don't know if the solution above creates a problem; I know that releasing COM object won't create any.


Andrei Smolin
Add-in Express Team Leader
Posted 29 May, 2015 07:33:58 Top
Joachim Weber


Guest


Thank you too Andrei,

I will try it and inform you. By the way I have another questions: a) How can I find out if the currentFolder is an contact, appointment or mail folder and b) I will compare folders by their type , do you have an example for me how I can do this.

Best Regards
Joachim
Posted 29 May, 2015 08:32:50 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Uou need to use MAPIFolder.DefaultItemType, see https://msdn.microsoft.com/en-us/library/office/ff865360%28v=office.15%29.aspx. We don't have such an example.


Andrei Smolin
Add-in Express Team Leader
Posted 29 May, 2015 08:52:07 Top