Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Need steps for getting all Outlook contacts
Ask a questionAsk a question
 

General DiscussionNeed steps for getting all Outlook contacts

  • Wednesday, November 04, 2009 5:36 AMVivekanandan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello,

    We got Outlook Contacts by using GetDefaultFolder() on Session object of Outlook Application. In this scheme we can not get all folders contacts. For example, I have two Contacts folders on my outlook Addressbook and can get from first contact folder and can not get the another one.

    OutLook.MAPIFolder fldContacts = (OutLook.MAPIFolder)outlookObj.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderContacts);


    We also tried using AddressLists collection from the same Session object and can get all address entries. But From the AddressEntry object, We can not get the Contact Firstname and Lastname. The AddressEntry class provives only email and Display name. But we need the contact's Firstname and Lastname.

    foreach (OutLook.AddressList addList in outlookObj.Session.AddressLists)
                    {
                        foreach (OutLook.AddressEntry addEntry in addList.AddressEntries)
                        {
    }
    }

    Could you give us the procedure for getting all Outlook contacts FirstName, LastName and Email?

    Thanks,
    Vivekanandan

All Replies

  • Wednesday, November 04, 2009 6:49 AMJose Anton Bautista Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi vivekanandan!

    I'm not sure what you mean by "can get from first contact folder and can not get the another one".
    Have you tried enumerating all folders that contain contact items?


    foreach (Outlook.MAPIFolder folder in outlookObj.Session.Folders)
    {
        if (folder.DefaultItemType == Outlook.olItemType.olContactItem)
        {
            // Get all contacts in the current folder
            foreach (Outlook.ContactItem contact in folder.Items)
            {

            }
        }
    }

  • Wednesday, November 04, 2009 4:22 PMVivekanandan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Mr. Jose Anton Bautista,

    Thanks, We tried the above code and not able to get any single folder the type Outlook.olItemType.olContactItem. Could you guide how to convert AddressEntry in to Microsoft.Office.Interop.Outlook._ContactItem object then we can easily able to get FirstName and LastName or alternate way to get all contacts from Outlook?

    Thanks,
    Vivekanandan
  • Wednesday, November 04, 2009 6:47 PMHelmut ObertannerMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Vivekanandan,

    can you give us a hint -> what exactly do you mean with Contacts.

    Dou you mean all contacts visible in the Outlook Folder Structure (Left Panel, click on folders)
    Or - do you mean the Addressentries of the SelectRecipient Dialog (Globals Addresslist (Exchange, AD) + Outlook Folders +  Public Folders that have the Property "Show this Folder as an Email Addressbook" set.

    So what Contacts do you mean? -> Global Addresslist?
    -> Here is a script sample: http://www.infinitec.de/post/2005/02/How-to-get-the-Global-Address-List-programatically.aspx

    Also see this:

    http://support.microsoft.com/kb/313799/en-us

    Hope this helps,
    greets - Helmut
     
    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
  • Wednesday, November 11, 2009 9:58 AMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to "Question" by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.