Create a Contact item

This example shows how to create a contact item and set various properties for the contact.

Example

Note

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007.

An Outlook ContactItem object has more than 100 built-in properties such as Department, CompanyName, OfficeLocation, and JobTitle. You can add custom properties, if a built-in property is not available, by using the UserProperties collection. Once you create a ContactItem, you can set its properties.

In the following code example, CreateContactExample creates a ContactItem and sets commonly used properties for that object. It then calls the ShowCheckPhoneDialog(OlContactPhoneNumber) method on the ContactItem object. The ShowCheckPhoneDialog method allows the user to resolve a phone number based on local dialing conventions.

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void CreateContactExample()
{
    Outlook.ContactItem contact = Application.CreateItem(
        Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
    contact.FirstName = "Mellissa";
    contact.LastName = "MacBeth";
    contact.JobTitle = "Account Representative";
    contact.CompanyName = "Contoso Ltd.";
    contact.OfficeLocation = "36/2529";
    contact.BusinessTelephoneNumber = "4255551212 x432";
    contact.WebPage = "https://www.contoso.com";
    contact.BusinessAddressStreet = "1 Microsoft Way";
    contact.BusinessAddressCity = "Redmond";
    contact.BusinessAddressState = "WA";
    contact.BusinessAddressPostalCode = "98052";
    contact.BusinessAddressCountry =
        "United States of America";
    contact.Email1Address = "melissa@contoso.com";
    contact.Email1AddressType = "SMTP";
    contact.Email1DisplayName =
        "Melissa MacBeth (mellissa@contoso.com)";
    contact.Display(false);
    contact.ShowCheckPhoneDialog(
        Outlook.OlContactPhoneNumber.
        olContactPhoneBusiness);
}

See also