查看完整版本: [-- Exchange Server 2007 二次开发 (五) --]

Exchange技术论坛 -> Exchange 二次开发 -> Exchange Server 2007 二次开发 (五) [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

tata 2011-02-19 14:33

Exchange Server 2007 二次开发 (五)


创建联系人,这段代码来自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]        }


script 2011-03-09 15:08
Exchange Server 2007 二次开发是非常重要的。我要好好的学习。

asd135521591 2013-02-20 15:52


查看完整版本: [-- Exchange Server 2007 二次开发 (五) --] [-- top --]



Powered by phpwind v8.7.1 Code ©2003-2011 phpwind
Time 0.025650 second(s),query:6 Gzip enabled