The following code sample show how to remove or delete all contacts in outlook using c# programming language.
Before using this code sample you need to add reference of ‘Microsoft.Office.Interop.Outlook’ library.
[C#t]
private void DeleteAllContacts() { Outlook.Application oApp = default(Outlook.Application); oApp = Interaction.CreateObject("Outlook.Application"); Outlook.NameSpace oNs = default(Outlook.NameSpace); oNs = oApp.GetNamespace("MAPI"); Outlook.MAPIFolder oFolder = default(Outlook.MAPIFolder); Outlook.ContactItem ContactItem = default(Outlook.ContactItem); oFolder = oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); for (long i = 0; i <= oFolder.Items.Count - 1; i++) { try { ContactItem = oFolder.Items.Item(i); ContactItem.Delete(); } catch (System.Exception ex) { } } MessageBox.Show("All contacts have been deleted successfully"); oFolder = null; oNs = null; oApp = null; }
Hi,
thanks’s for that code, but how can i delete all contact Items from “DeletedItemsFolder”, which have a special property like ContactItem.user3=”test”?
Thanks
regards
Rene
hello Rene
try this code for deleting contact items from ‘Deleted items’ folder:
thanks
let me know about the result