建立聯繫人專案
此範例示範如何建立聯繫人專案,並設定聯繫人的各種屬性。
範例
注意事項
下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。
Outlook ContactItem 對象有超過 100 個內建屬性,例如 Department、 CompanyName、 OfficeLocation 和 JobTitle。 如果內建屬性無法使用,您可以使用 UserProperties 集合來新增自定義屬性。 建立 ContactItem 之後,您可以設定其屬性。
在下列程式代碼範例中,CreateContactExample 會建立 ContactItem ,並設定該物件的常用屬性。 然後在 ContactItem 物件上呼叫 ShowCheckPhoneDialog (OlContactPhoneNumber) 方法。 ShowCheckPhoneDialog 方法可讓用戶根據本機撥號慣例來解析電話號碼。
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 CreateContactExample()
{
Outlook.ContactItem contact = Application.CreateItem(
Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
contact.FirstName = "Mellissa";
contact.LastName = "MacBeth";
contact.JobTitle = "Account Representative";
contact.CompanyName = "Contoso Ltd.";
contact.OfficeLocation = "36/2529";
contact.BusinessTelephoneNumber = "4255551212 x432";
contact.WebPage = "https://www.contoso.com";
contact.BusinessAddressStreet = "1 Microsoft Way";
contact.BusinessAddressCity = "Redmond";
contact.BusinessAddressState = "WA";
contact.BusinessAddressPostalCode = "98052";
contact.BusinessAddressCountry =
"United States of America";
contact.Email1Address = "melissa@contoso.com";
contact.Email1AddressType = "SMTP";
contact.Email1DisplayName =
"Melissa MacBeth (mellissa@contoso.com)";
contact.Display(false);
contact.ShowCheckPhoneDialog(
Outlook.OlContactPhoneNumber.
olContactPhoneBusiness);
}