共用方式為


顯示收件者的共用行事曆

此範例示範如何使用 CreateRecipient (String) GetSharedDefaultFolder (Recipient、 OlDefaultFolders) 方法來顯示收件者的 共用行事歷。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

MailItem 物件之類的可傳送專案一律會公開 Recipients 屬性,進而讓您存取可傳送專案的 Recipients 集合。 若要建立未系結至專案 Recipients 集合的 Recipient 物件,請使用 NameSpace 物件的 CreateRecipient (String) 方法。 然後將這個未系結 的 Recipient 對象傳遞至 GetSharedDefaultFolder (Recipient, OlDefaultFolders) 方法,這會傳回共用的 Exchange 資料夾。 然後,您可以開啟共用 Exchange 資料夾,並在總管視窗中顯示該資料夾。 GetSharedDefaultFolder 用於委派有權存取委派者資料夾的Exchange委派案例中。 將 Recipient 物件傳遞至 GetSharedDefaultFolder 方法之前,您必須先解析它。 若要解析 Recipient 物件,請呼叫其 Resolve () 方法。

在下列程式代碼範例中,DisplayManagerCalendar 會開啟並顯示目前使用者管理員的 Calendar 資料夾,方法是呼叫 CreateRecipientGetSharedDefaultFolder。 如果使用者沒有開啟管理員 [行事曆] 資料夾的許可權或發生錯誤,就會顯示警示對話方塊。

注意事項

當您使用 Namespace物件的CreateRecipient 方法或 Recipients 集合的 Add (String) 方法建立 Recipient 物件時,您必須提供收件者名稱。 接著會針對此名稱解析 收件者 。 收件者名稱可以採用下列任何格式:

  • 顯示名稱
  • 別名
  • 簡易郵件傳送通訊協定 (SMTP) 位址

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 DisplayManagerCalendar()
{
    Outlook.AddressEntry addrEntry =
        Application.Session.CurrentUser.AddressEntry;
    if (addrEntry.Type == "EX")
    {
        Outlook.ExchangeUser manager =
            Application.Session.CurrentUser.
            AddressEntry.GetExchangeUser().GetExchangeUserManager();
        if (manager != null)
        {
            Outlook.Recipient recip =
                Application.Session.CreateRecipient(manager.Name);
            if (recip.Resolve())
            {
                try
                {
                    Outlook.Folder folder =
                        Application.Session.GetSharedDefaultFolder(
                        recip, Outlook.OlDefaultFolders.olFolderCalendar)
                        as Outlook.Folder;
                    folder.Display();
                }
                catch
                {
                    MessageBox.Show("Could not open manager's calendar.",
                        "GetSharedDefaultFolder Example",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
        }
    }
}

另請參閱