Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Access WAB or MS Outlook Address book via C#
Ask a questionAsk a question
 

AnswerAccess WAB or MS Outlook Address book via C#

  • Thursday, July 26, 2007 1:42 AMkitcad Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Hi!

     

    I am trying to access WAB or MS Outlook Address book  via C# in VS 2005 under Vista.

    Any idea? I have tried to find out from web but look like there are a lot of way to do it and different MS Outlook version (Ms Office 2003or XP or 2007) have diff way to code.

     

    Alex

Answers

  • Friday, July 27, 2007 10:59 AMSue Mosher - Outlook MVPMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    The Global Address List (GAL) is an address book derived from Active Directory data maintained by the network administrator on the server.

     

    If you want to access a user's Outlook contacts, use the Namespace.GetDefaultFolder method to return the contacts folder as a MAPIFolder or (in Outlook 2007) Folder object, then iterate that folder's Items or use the Items.Find or Items.Restrict method to filter for specific criteria.

All Replies

  • Thursday, July 26, 2007 12:54 PMSue Mosher - Outlook MVPMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    What exactly are you seeking to do with the Outlook Address Book? It's accessible through a couple of different techniques in the OUtlook object model, but the details depend on what version of Outlook your add-in is written for.

     

    WAB would be beyond the scope of this forum.

  • Thursday, July 26, 2007 6:56 PMSteveAbram Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Are you trying to get information from the users address book or the global address book? If the global address book, I would use LDAP and read it that way.

  • Friday, July 27, 2007 5:07 AMkitcad Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    i am trying to retrieve contact from outlook 2007.

  • Friday, July 27, 2007 5:08 AMkitcad Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    might explaint diff user and global address book? how to retrieve contact from them?

  • Friday, July 27, 2007 10:59 AMSue Mosher - Outlook MVPMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    The Global Address List (GAL) is an address book derived from Active Directory data maintained by the network administrator on the server.

     

    If you want to access a user's Outlook contacts, use the Namespace.GetDefaultFolder method to return the contacts folder as a MAPIFolder or (in Outlook 2007) Folder object, then iterate that folder's Items or use the Items.Find or Items.Restrict method to filter for specific criteria.

  • Sunday, July 29, 2007 1:27 PMkitcad Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thanks. I am able to get contact folder called "contact". But inside WAB, there are more than one contact folders,e.g. created by company which is list of employees contact list catogarise by country.

     

    How to access these?

     

     

    Alex

  • Sunday, July 29, 2007 1:32 PMSue Mosher - Outlook MVPMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    <P align=left><FONT face=Arial>It sounds like you're still confused about what address book you're looking at. Outlook does not use the WIndows Address Book. That is a feature of Outlook Express and Windows Mail. </FONT></P>
    <P align=left>&nbsp;</P>
    <P align=left>Central company address lists would be part of the Global Address List. You can access those lists through the Namespace.AddressLists collection or access the data, which is stored in Active Directory,&nbsp;directly through LDAP as Steve already pointed out. </P>
  • Wednesday, August 01, 2007 9:39 AMkitcad Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Great to hear from you again. I can see you all over in Outlook forums.

    Back on track.

    I managed to get GAL and now i need to get particular GAL folder item detail e.g. FullName, email, tel and etc just like contactitem.

     

    objOutlook = new Outlook.Application();

    objNS = objOutlook.GetNamespace("MAPI");

     

    Outlook.AddressLists objAddressList = objNS.AddressLists;

     

    // Redemption.AddressLists rals = (Redemption.AddressLists)

     

     for (int i = 1; i < (objAddressList.Count + 1); i++)

     {

     string stest = objAddressList.Item(i).Name;

     }

     

    using below line will only get the name. how to get more than that e.g. email, tel, fax without using CDO?

     

    string sname1 = objAddressList.Item(20).c.Item(1).Name;

     

     

    I'm using Vista business, VS2005 and Outlook 2007.

  • Wednesday, August 01, 2007 11:42 AMSue Mosher - Outlook MVPMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Use the new PropertyAccessor object and its GetProperty and GetProperties methods to get to information other than that exposed in the properties of the AddresssEntry object; see http://msdn2.microsoft.com/en-us/library/microsoft.office.interop.outlook._propertyaccessor_members.aspx.

     

    FYI, If you have VS set to use online help, you can now get to details about all Outlook objects just by putting the cursor on an Outlook type and pressing F1; see http://blogs.msdn.com/rgregg/archive/2007/07/26/outlook-2007-pia-documentation-online.aspx.

  • Wednesday, August 01, 2007 2:42 PMkitcad Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    HI! Sue Mosher,

    I'm sorry need your help  again to give an example how to use GetProperty or GetProperties for GAL?

     

    Alex

  • Monday, August 13, 2007 12:16 AMJoeCastro [MSFT] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    To hopefully help with the original question, I've been working on a C# library for accessing WAB contacts in Vista, available at www.codeplex.com/Contacts.  I realize it's outside the scope of this forum, but I stumbled across this post and thought I'd mention it.

  • Tuesday, August 14, 2007 3:06 AMkitcad Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    sorry, recently stuck with other project. I'm going to look on it next week.  Thanks 1st.

  • Monday, September 17, 2007 2:23 PMgppradeep Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Sue Mosher,

     

                                          I want to fetch Global Address List(GAL) contacts in to my ASP.NET application, i am using Exchange Server 2003, outlook 2003, .NET Framework 1.2, using MAPI i was able to fetch only Name and Address value of the contacts in GAL, PropertyAccessor object is not available to me as i am using Microsoft Outllok 11.0 object library so is there any other method to achieve this, i mean in outlook 2003 using MAPI is there any other method to retrive all the properties of contacts in GAL. Thanks.

  • Wednesday, April 23, 2008 11:40 AMMauro Batista Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi

     

    I have exactly the same problem with only a diference iam using c#, did you solve it? if yes , can you tell me please how?

     

     

     

    best regards,

    Mauro Batista

  • Wednesday, April 23, 2008 4:30 PMSue Mosher - Outlook MVPMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Mauro, given that at least three different scenarios have been discussed in this thread, you need to define exactly what "the same problem" means for you, including the version(s) of Outlook you are supporting. Also explain which of the posted solutions you've already tried, giving relevant code snippets. You might want to start a new thread on this issue, as this one is rather stale.
  • Wednesday, April 23, 2008 4:36 PMMauro Batista Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Sue

     

    Sorry i will create a new thread with my problem

     

    best regards

    Mauro Batista

  • Tuesday, November 04, 2008 10:06 AMjohnduggan1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi
    I am trying to access the gal address book in outlook 2003 and retrive the telephone number. I am only  only a beinger at C# does any one have the code
    Regards
    John