共用方式為


取得目前使用者的相關信息

此範例示範如何取得目前用戶的資訊,例如名稱、職稱和電話號碼。

範例

注意事項

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

若要從 AddressEntry 物件取得 ExchangeUser 物件,請在 AddressEntry 物件上呼叫 GetExchangeUser () 方法。 在下列程式中,GetCurrentUserInfo 會使用 CurrentUser 屬性取得 Recipient 物件的 AddressEntry 屬性。 如果 AddressEntry 物件代表 Exchange 信箱使用者,GetCurrentUserInfo 會呼叫 GetExchangeUser 方法,並傳回 ExchangeUser 物件。 NamePrimarySmtpAddressJobTitleDepartmentOfficeLocationBusinessTelephoneNumberMobileTelephoneNumber 屬性會寫入接聽程式集合的追蹤接聽程式。

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 GetCurrentUserInfo()
{
    Outlook.AddressEntry addrEntry =
        Application.Session.CurrentUser.AddressEntry;
    if (addrEntry.Type == "EX")
    {
        Outlook.ExchangeUser currentUser =
            Application.Session.CurrentUser.
            AddressEntry.GetExchangeUser();
        if (currentUser != null)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Name: "
                + currentUser.Name);
            sb.AppendLine("STMP address: "
                + currentUser.PrimarySmtpAddress);
            sb.AppendLine("Title: "
                + currentUser.JobTitle);
            sb.AppendLine("Department: "
                + currentUser.Department);
            sb.AppendLine("Location: "
                + currentUser.OfficeLocation);
            sb.AppendLine("Business phone: "
                + currentUser.BusinessTelephoneNumber);
            sb.AppendLine("Mobile phone: "
                + currentUser.MobileTelephoneNumber);
            Debug.WriteLine(sb.ToString());
        }
    }
}

另請參閱