1
votes

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?

1
I am not sure that complete removal of the adress book is even possible, because its built in by construction. - Freeman
Does it matter if I'm the one that created the address book? It's not any of the default ones. I'm adding a subfolder to the default contacts folder and then I set its flag ShowAsOutlookAB to true. 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
From what i know you can only create folders, not adress books, the folders can indeed be removed but i doubt the adress book part can be removed. Looks like a question for microsoft support. - Freeman
I recognize the direction in which you're headed. That's the impression I've got too. That's why I create a subfolder in contacts and then, manually set it to showable in Outlook as an address book. It feels plain wrong to be able to create stuff but not to remove them... - Konrad Viltersten
yup, just the average ms products :) - Freeman

1 Answers

1
votes

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 Deleted directory 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. :)