Expand Minimize
0 out of 8 rated this helpful - Rate this topic

How to: Delete Outlook Contacts

Note Required applications

The code example in this topic can be compiled only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005

    -or-

    Visual Studio Team System

  • Microsoft Office Outlook 2003

NoteNote

This code does not compile if you use the VSTO 2005 SE version of the Outlook 2003 add-in project template. For more information, see Getting Started Programming Application-Level Add-ins.

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

Example

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

private void DeleteContact(string lastName, string firstName)
{
    Outlook.ContactItem contact =
        this.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();
    }
}

See Also

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.