How to: Programmatically Delete Outlook Contacts

 

This example deletes a contact. The example assumes that a contact named "Armando Pinto" exists in the Contacts folder.

Applies to: The information in this topic applies to VSTO add-in projects for Outlook. For more information, see Features Available by Office Application and Project Type.

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            DeleteContact("Pinto", "Armando");
        }

        private void DeleteContact(string lastName, string firstName)
        {
            Outlook.ContactItem contact =
                this.Application.GetNamespace("MAPI").
            GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).
            Items.
            Find(
            string.Format("[LastName]='{0}' AND [FirstName]='{1}'",
            lastName, firstName))
            as Outlook.ContactItem;

            if (contact != null)
            {
                contact.Delete();
            }
        }

Working with Contact Items
How to: Programmatically Search for a Specific Contact
How to: Programmatically Access Outlook Contacts

Show: