Check a manager's response to a meeting request
This example illustrates how to use the GetExchangeUser() and GetExchangeUserManager() methods to check the status of the response of the current user's manager to a meeting request.
Example
Note
The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007.
To determine whether a given recipient has accepted or declined a requested meeting, use the MeetingResponseStatus property of the Recipient object from the Recipients collection associated with the AppointmentItem object.
In the following code example, CheckManagerResponseStatus takes in an AppointmentItem object as a parameter. CheckManagerResponseStatus gets the ExchangeUser object by calling the GetExchangeUser method on the current user. CheckManagerResponseStatus then gets the ExchangeUser object that is associated with the current user’s manager by calling the GetExchangeUserManager method. By using the CompareEntryIDs(String, String) method of the NameSpace object, the example then checks whether the Recipient object associated with the AppointmentItem object is the same as the ExchangeUser object that represents the user’s manager. If CompareEntryIDs returns true, the user’s manager is found in the Recipients collection, and CheckManagerResponseStatus returns the manager’s MeetingResponseStatus. If CompareEntryIDs returns false, CheckManagerResponseStatus returns a null reference.
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 Object CheckManagerResponseStatus(Outlook.AppointmentItem appt)
{
try
{
if (appt == null)
{
throw new ArgumentNullException();
}
Outlook.AddressEntry user =
Application.Session.CurrentUser.AddressEntry;
Outlook.ExchangeUser userEx = user.GetExchangeUser();
if (userEx == null)
{
return null;
}
Outlook.ExchangeUser manager =
userEx.GetExchangeUserManager();
if (manager == null)
{
return null;
}
foreach (Outlook.Recipient recip in appt.Recipients)
{
if (Application.Session.CompareEntryIDs(
recip.AddressEntry.ID, manager.ID))
{
return recip.MeetingResponseStatus;
}
}
return null;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
return null;
}
}