Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

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

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.

Applies to: The information in this topic applies to application-level projects for Outlook 2007 and Outlook 2010. For more information, see Features Available by Office Application and Project Type.


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

    Outlook.MAPIFolder contactFolder = this.
        Application.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");
    }
}


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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.