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 |
|
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 |
|
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 |
|
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 |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
|