切换到宽版
  • 9969阅读
  • 2回复

[分享]Exchange Server 2007 二次开发 (五) [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-02-19

创建联系人,这段代码来自SDK:
1    public static void CreateContact(ExchangeServiceBinding esb)
2        {
3            // Create an object of create item type.
4            CreateItemType createItemType = new CreateItemType();
5
6            // Because you are creating a contact, save the item in the Contacts folder.
7            createItemType.SavedItemFolderId = new TargetFolderIdType();
8            DistinguishedFolderIdType contactsFolder = new DistinguishedFolderIdType();
9            contactsFolder.Id = DistinguishedFolderIdNameType.contacts;
10
11            createItemType.SavedItemFolderId.Item = contactsFolder;
12
13            createItemType.Items = new NonEmptyArrayOfAllItemsType();
14            createItemType.Items.Items = new ItemType[1];
15
16            // Create a contact item type.
17            ContactItemType contactItem = new ContactItemType();
18
19            // Set the relevant properties on the contact.
20            contactItem.FileAs = "Friend A";
21
22            // Set the contact name and job information.
23            contactItem.GivenName = "Don";
24            contactItem.Surname = "Hall";
25            contactItem.CompanyName = "AdventureWorks";
26            contactItem.JobTitle = "Software Engineer";
27
28            // Set a single e-mail address for the contact.
29            contactItem.EmailAddresses = new EmailAddressDictionaryEntryType[1];
30            EmailAddressDictionaryEntryType address = new EmailAddressDictionaryEntryType();
31[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            address.Key = EmailAddressKeyType.EmailAddress1;
32[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            address.Value = "don@example.com";
33[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            contactItem.EmailAddresses[0] = address;
34[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
35[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Set a single contact physical address.
36[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            contactItem.PhysicalAddresses = new PhysicalAddressDictionaryEntryType[1];
37[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            PhysicalAddressDictionaryEntryType physicalAddress = new PhysicalAddressDictionaryEntryType();
38[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            physicalAddress.Key = PhysicalAddressKeyType.Home;
39[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            physicalAddress.Street = "1234 56 Ave NE";
40[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            physicalAddress.City = "La Habra Heights";
41[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            physicalAddress.CountryOrRegion = "United States";
42[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            physicalAddress.PostalCode = "98072";
43[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
44[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            contactItem.PhysicalAddresses[0] = physicalAddress;
45[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
46[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Set the contact telephone number.
47[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            contactItem.PhoneNumbers = new PhoneNumberDictionaryEntryType[1];
48[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            PhoneNumberDictionaryEntryType phoneEntry = new PhoneNumberDictionaryEntryType();
49[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            phoneEntry.Key = PhoneNumberKeyType.BusinessPhone;
50[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            phoneEntry.Value = "5625550100";
51[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
52[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            contactItem.PhoneNumbers[0] = phoneEntry;
53[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
54[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            createItemType.Items.Items[0] = contactItem;
55[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
56[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Send the request to create the contact item; receive the response.
57[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            CreateItemResponseType createItemResponse = esb.CreateItem(createItemType);
58[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]
59[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            // Check the results of the request.
60[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]            if (createItemResponse.ResponseMessages.Items.Length > 0 &&
61[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                createItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
62[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif[/img]            {
63[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                ItemInfoResponseMessageType responseMessage = createItemResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
64[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                ContactItemType contactResponse = responseMessage.Items.Items[0] as ContactItemType;
65[img]http://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif[/img]                Console.WriteLine("Created Contact Item with Id {0} and ChangeKey {1}", contactResponse.ItemId.Id, contactResponse.ItemId.ChangeKey);
66[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif[/img]            }

67[img]http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif[/img]        }

分享到
只看该作者 1楼  发表于: 2011-03-09
Exchange Server 2007 二次开发是非常重要的。我要好好的学习。
只看该作者 2楼  发表于: 2013-02-20
快速回复
限60 字节
 
上一个 下一个