VB.Net creating Contact in Outlook

I have a need to be able to create a Contact in a Users Outlook Address book. Here is some more info, some users have more then one  Email account which means multiple address books. So here is my question, how do I save to the default address book ? Is there a way to get a list of address books for a user and have him chose where to save. Also I have the below sample code but when I run it it does not throw an error nor do I find the contact in any of my address books

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        ' Create an Outlook application.
        Dim outApplication As Outlook.Application = New Outlook.Application()

        ' Get the namespace and the logon.
        Dim outNamSpace As Outlook.NameSpace = outApplication.GetNamespace("MAPI")

        ' Create a new contact item.
        Dim NewContact As Outlook.ContactItem = outApplication.CreateItem(Outlook.OlItemType.olContactItem)

        ' Set some common properties.
        NewContact.FirstName = "Author"
        NewContact.FullName = "Author Code"
        NewContact.Title = "Client"
        NewContact.Birthday = Convert.ToDateTime("5/4/1969")
        NewContact.CompanyName = "AuthorCode"
        NewContact.Department = "Development"
        NewContact.Body = "Sample"
        NewContact.FileAs = "Authorcode"
        NewContact.Email1Address = "abc@hotmail.com"
        NewContact.Email2Address = "abc@live.com"
        NewContact.MailingAddress = "NewDelhi India"
        NewContact.Subject = "Contact crated from vb.net"
        NewContact.JobTitle = "Engineer"

        NewContact.Save()


        outApplication = Nothing
        outNamSpace = Nothing
        NewContact = Nothing

    End Sub

Open in new window

AlexPonnathAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ktaczalaCommented:
I ran this in Visual Studio 2015 against my Outlook 2013 and it adds the contact to my default contacts folder.

To see what the default contact folder is, add these lines to you code just before you execute the save command.
        Dim default_folder As outlook.Folder
        default_folder = outNamSpace.GetDefaultFolder(outlook.OlDefaultFolders.olFolderContacts)
        MessageBox.Show(default_folder.Name)

Open in new window

Also here's another link that someone has posted some code doing something similar.
Creating Contacts in outlook
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.