Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Use the Select Names Dialog Box to Obtain and Assign Recipients to an Appointment

This example shows how to use the Select Names dialog box to obtain and assign recipients to an appointment item.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

To display the Select Names dialog box, call the Display() method of the SelectNamesDialog object. Once the Select Names dialog box is displayed to the user, code execution halts until the user clicks OK or closes the dialog box. To set initial recipients to display in the dialog box, or to get the recipients selected in the dialog box, use the Recipients property of the SelectNamesDialog object. This returns a Recipients collection that is associated with the SelectNamesDialog. To add a Recipient object to the Recipients collection for the SelectNamesDialog, use the Add method for the collection and specify the Type property of the Recipient object.

In the following code example, DemoSelectNamesDialogRecipients creates an AppointmentItem object and sets some of its properties. It then creates a SelectNamesDialog and uses the SetDefaultDisplayMode(OlDefaultSelectNamesDisplayMode) method to set a meeting display mode for the Select Names dialog box. The example populates the Resource recipient selector with the string "Conf Room 36/2739". Once the dialog box is displayed to the user, the code enumerates the Recipients collection that is associated with this instance of SelectNamesDialog and adds those recipients to the appointment that was created. Finally, the example displays the meeting request to the user.

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 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 DemoSelectNamesDialogRecipients()
{
    Outlook.AppointmentItem appt = Application.CreateItem(
        Outlook.OlItemType.olAppointmentItem)
        as Outlook.AppointmentItem;
    appt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
    appt.Subject = "Team Morale Event";
    appt.Start = DateTime.Parse("5/17/2007 11:00 AM");
    appt.End = DateTime.Parse("5/17/2007 12:00 PM");
    Outlook.SelectNamesDialog snd =
        Application.Session.GetSelectNamesDialog();
    snd.SetDefaultDisplayMode(
        Outlook.OlDefaultSelectNamesDisplayMode.olDefaultMeeting);
    Outlook.Recipient confRoom =
        snd.Recipients.Add("Conf Room 36/2739");
    // Explicitly specify Recipient.Type.
    confRoom.Type = (int)Outlook.OlMeetingRecipientType.olResource;
    snd.Recipients.ResolveAll();
    snd.Display();
    // Add Recipients to meeting request.
    Outlook.Recipients recips = snd.Recipients;
    if (recips.Count > 0)
    {
        foreach (Outlook.Recipient recip in recips)
        {
            appt.Recipients.Add(recip.Name);
        }
    }
    appt.Recipients.ResolveAll();
    appt.Display(false);
}

Other Resources

Show:
© 2014 Microsoft