How to: Display the Select Names Dialog Box to Resolve Recipients

This example attempts to resolve the recipients provided by the recips parameter, and displays the Outlook Select Names dialog box for each recipient that is ambiguous and cannot be resolved.

This code sample calls the SelectNamesDialog object to display the Select Names dialog box which shows the Outlook address book. Through this dialog box, the user can select a name from the address book. If the name is not resolved, the recipient will be removed from recips. If the name is resolved, then the code sample will return the AddressEntry object of the recipient to recips.

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

using Outlook = Microsoft.Office.Interop.Outlook;
private void ResolveRecipients(Outlook.Recipients recips)
{
    if (recips == null)
    {
        throw new ArgumentNullException();
    }
    if (recips.ResolveAll())
    {
        return;
    }
    else
    {
        for (int i = recips.Count; i > 0; i--)
        {
            if (!recips[i].Resolve())
            {
                Outlook.SelectNamesDialog snd =
                    Application.Session.
                    GetSelectNamesDialog();
                snd.Recipients.Add(recips[i].Name);
                snd.NumberOfRecipientSelectors =
                    Outlook.OlRecipientSelectors.olShowTo;
                snd.AllowMultipleSelection = false;
                snd.Display();
                if (!snd.Recipients.ResolveAll())
                {
                    recips.Remove(i);
                }
                else
                {
                    recips.Remove(i);
                    recips.Add(snd.Recipients[1].Address);
                }
                snd = null;
            }
        }
    }
}

Other Resources

Community Additions

ADD
Show:
© 2014 Microsoft