取得 Exchange 使用者管理員的可用性資訊
本範例會顯示用戶經理行事曆中下一個 60 分鐘的可用時段。
範例
此程式代碼範例會檢查目前的使用者是否為 Exchange 使用者。 如果是,而且目前使用者有管理員,則會呼叫 AddressEntry 物件的 GetExchangeUser 方法和 ExchangeUser 物件的 GetExchangeUserManager 方法,以取得管理員的資訊。 管理員的資訊包含在 ExchangeUser 物件中,其中包含經理的空閒/忙碌排程。
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 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#.
Imports Outlook = Microsoft.Office.Interop.Outlook
using Outlook = Microsoft.Office.Interop.Outlook;
Private Sub GetManagerOpenInterval()
Const slotLength As Integer = 60
Dim addrEntry As Outlook.AddressEntry = _
Application.Session.CurrentUser.AddressEntry
If addrEntry.Type = "EX" Then
Dim manager As Outlook.ExchangeUser = _
Application.Session.CurrentUser. _
AddressEntry.GetExchangeUser(). _
GetExchangeUserManager()
If Not (manager Is Nothing) Then
Dim freeBusy As String = _
manager.GetFreeBusy(DateTime.Now, slotLength, True)
For i As Integer = 1 To freeBusy.Length - 1
If (freeBusy.Substring(i, 1) = "0") Then
' Get number of minutes into
' the day for free interval
Dim busySlot As Double = (i - 1) * slotLength
' Get an actual date/time
Dim dateBusySlot As DateTime = _
DateTime.Now.Date.AddMinutes(busySlot)
If (dateBusySlot.TimeOfDay >= _
DateTime.Parse("8:00 AM").TimeOfDay And _
dateBusySlot.TimeOfDay <= _
DateTime.Parse("5:00 PM").TimeOfDay And _
Not (dateBusySlot.DayOfWeek = _
DayOfWeek.Saturday Or _
dateBusySlot.DayOfWeek = DayOfWeek.Sunday))Then
Dim sb As StringBuilder = New StringBuilder()
sb.AppendLine( _
manager.Name & " first open interval:")
sb.AppendLine(dateBusySlot.ToString("f"))
Debug.WriteLine(sb.ToString())
End If
End If
Next
End If
End If
End Sub
private void GetManagerOpenInterval()
{
const int slotLength = 60;
Outlook.AddressEntry addrEntry =
Application.Session.CurrentUser.AddressEntry;
if (addrEntry.Type == "EX")
{
Outlook.ExchangeUser manager =
Application.Session.CurrentUser.
AddressEntry.GetExchangeUser().GetExchangeUserManager();
if (manager != null)
{
string freeBusy = manager.GetFreeBusy(
DateTime.Now, slotLength, true);
for (int i = 1; i < freeBusy.Length; i++)
{
if (freeBusy.Substring(i, 1) == "0")
{
// Get number of minutes into
// the day for free interval
double busySlot = (i - 1) * slotLength;
// Get an actual date/time
DateTime dateBusySlot =
DateTime.Now.Date.AddMinutes(busySlot);
if (dateBusySlot.TimeOfDay >=
DateTime.Parse("8:00 AM").TimeOfDay &
dateBusySlot.TimeOfDay <=
DateTime.Parse("5:00 PM").TimeOfDay &
!(dateBusySlot.DayOfWeek ==
DayOfWeek.Saturday |
dateBusySlot.DayOfWeek == DayOfWeek.Sunday))
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(manager.Name
+ " first open interval:");
sb.AppendLine(dateBusySlot.ToString("f"));
Debug.WriteLine(sb.ToString());
}
}
}
}
}
}