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.

Example

Note

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

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 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 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);
}

See also