Export (0) Print
Expand All
Expand Minimize

How to: Read Data from a Custom Field of an Item

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 reads data from a custom field of a contact item. This example checks contacts in a folder named Picnic for a value in a custom text field named Picnic. The code displays the name of all contacts that have the value Potato Salad.

Example

private void ThisApplication_Startup(object sender, 
    System.EventArgs e)
{
    System.Text.StringBuilder result = 
        new System.Text.StringBuilder();

    Outlook.MAPIFolder contactFolder = this.
        GetNamespace("MAPI").
        GetDefaultFolder(Outlook.OlDefaultFolders.
        olFolderContacts).Folders["Picnic"];
    Outlook.Items picnicMembers = contactFolder.Items.
        Restrict("[Picnic]='Potato Salad'");
    foreach (Outlook.ContactItem contact in picnicMembers)
    {
        result.AppendLine(contact.FullName);
    }

    if (result.Length > 0)
    {
        MessageBox.Show(result.ToString(), "Potato Salad");
    }
    else
    {
        MessageBox.Show("No contacts are assigned potato salad"
            + " for the picnic.", "Potato Salad");
    }
}

Robust Programming

A COMException exception is thrown if the custom contact folder Picnic is not found in the folders collection. You can catch this exception and create the folder if it is missing.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft