问题
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