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?
I’ve done a mistake like that but with a different entity, although still in Outlook. The recommendation I’ve got was simply to ignore the issue. The
Deleteddirectory was full of items with the same name and the user was chacked when they discovered it.My solution, mostly to calm down the customer, was to rename the fields I knew that the end-user usually checked and add the text “Safely stored by Outlook maintnance“. Then the user was happy.
As far my knowledge streches, though, the short answer to your question is “sorry, you can’t”.
The long answer brings us to the option of removing the account and creating a new one but it wouldn’t surprise me if all the stuff then re-appeared all over again. 🙂