How to: Delete Outlook Contacts
Visual Studio 2005
| 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. |
|
Note |
|---|
|
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();
}
}
Note