How to: Delete Outlook Contacts

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Application-level projects

Microsoft Office version

  • Outlook 2003

  • Outlook 2007

For more information, see Features Available by Application and Project Type.

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

Example

Private Sub ThisAddIn_Startup(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Me.Startup
    DeleteContact("Pinto", "Armando")
End Sub 

Private Sub DeleteContact(ByVal lastName As String, _
ByVal firstName As String)
    Dim contact As Outlook.ContactItem = _
        TryCast(Me.Application.GetNamespace("MAPI").GetDefaultFolder( _
        Outlook.OlDefaultFolders.olFolderContacts).Items. _
        Find( _
        String.Format("[LastName]='{0}' AND [FirstName]='{1}'", _
        lastName, firstName)),  _
        Outlook.ContactItem)

    If (contact IsNot Nothing) Then
        contact.Delete()
    End If 
End Sub
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();
    }
}

See Also

Tasks

How to: Search for a Specific Contact

How to: Access Outlook Contacts

Concepts

Working with Contact Items