I'm running the code below and I was under the impression that it did what it was supposed to. However, it seems that Outlook never deletes the address book folder. It just sets .ShowAsOutlookABto false. It means that when I check if the folder exists at the next start-up of Outlook, the folder is there (although I didn't realize it since it didn't show in the UI).
Outlook.MAPIFolder defaultContactsFolder =
this.Application.GetNamespace("MAPI").GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderContacts);
defaultContactsFolder.Folders["My AB"].Delete();
I also tried the following code to make sure it's not something with my choice of library.
Outlook.Folder defaultContactsFolder =
this.Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderContacts) as Outlook.Folder;
Outlook.Folders contactFolders = defaultContactsFolder.Folders;
if (contactFolders.Cast<Outlook.Folder>().Where(
element => element.Name == _CrmkAddressBookName).Count() > 0)
contactFolders["My AB"].Delete();
In each case, the Delete is executed but results in merely hiding the address book from the user interface. I want the stupid thing gone for good!
How can I really remove a folder with an address book?
ShowAsOutlookABtotrue. Surely there's got to be a way to get rid of such thing?! What if I happen to have run a loop and created a gazillion of address book named "My AB xxx" and need to get rid of them? - Konrad Viltersten