Create a custom address book for Outlook 2010 programmatically

拈花ヽ惹草 提交于 2019-12-19 04:44:07

问题


I'd like to create a Custom Contact List (or address book as it's called) so that in Outlook the user will be looking at "Suggested Contact", "Contacts" etc., and then, "Custom Contacts". I went off and tried the following.

int count = this.Application.GetNamespace("MAPI").AddressLists.Count;

This gives me the value of 8. So, naturally, I've tried to Add something to the address list object but guess what - there's no such method. It's nothing strange about that, since the API clearly states that it's read-only object. However, I need to set up an address book/list (whatever it's called) for my client.

How do I add a new Address Book to Outlook?


回答1:


You can create an Outlook Address Book entry by using the following code:

Outlook.Folder contacts = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts) as Outlook.Folder;
Outlook.Folder addressBook = contacts.Folders.Add("Business Contacts", Outlook.OlDefaultFolders.olFolderContacts) as Outlook.Folder;
addressBook.ShowAsOutlookAB = true; // force display in Outlook Address Book
Outlook.ContactItem contact = addressBook.Items.Add();
contact.FullName = "Custom Industries, Inc.";
contact.Email1Address = "sales@customindustries.com";
contact.Save();


来源:https://stackoverflow.com/questions/12302683/create-a-custom-address-book-for-outlook-2010-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!