views:

404

answers:

4

i am able to look through the global address book using the outlook object model but is there anyway using the outlook object model from csharp i can get the following properties of a person:

City, State, Country/Region Alias Title Phone

i can't seem to find these properties on the AddressEntry object.


EDIT: I started a bounty here. I got this working using LDAP queries but they are such a pain. I am shocked that outlook doesn't support this in its simple api. i wanted to see if anyone else got it working or can explain / justify why outlook would not have support for this

A: 

As suggested in the other question, you might have to resort to direct access to the LDAP database underneath the addressbook.

whatnick
it just seems strange that this would not be exposed in the regular object model . .
ooo
how do i find out what ldap fields exist in my search results as these all seem to be strings
ooo
A: 

Is RDO and use to you? It offers quite a bit that Outlook blocks, including address data

RDO & C#

Remou
+3  A: 

Using Microsoft.Office.Interop.Outlook
You need to use the ExchangeUser object and the GetExchangeUser method on the AddressEntry Object.

using System;
using Microsoft.Office.Interop.Outlook;
static class Program
{
    static void Main(string[] args)
    {
        ExchangeUser oExUser;
        Application app = new Microsoft.Office.Interop.Outlook.Application();
        foreach (AddressList addressList in app.Session.AddressLists)
        {
            if (addressList.Name == "Global Address List")
            {
                foreach (AddressEntry item in addressList.AddressEntries)
                {
                    Console.WriteLine(item.Address);
                    oExUser = item.GetExchangeUser();
                    if (oExUser != null) 
                    {
                        Console.WriteLine(oExUser.FirstName);
                        Console.WriteLine(oExUser.LastName);
                        Console.WriteLine(oExUser.StreetAddress);
                        Console.WriteLine(oExUser.CompanyName);
                        Console.WriteLine(oExUser.Department);
                        Console.WriteLine(oExUser.OfficeLocation);
                        Console.WriteLine(oExUser.JobTitle);
                    }
                    Console.WriteLine();
                }
            }
        }
        Console.Read();
    }
}
Nathan Fisher
i am looking for the global address book here.. not your local contacts list
ooo
Applogies about the mixup. Updated my answer for the Global address book.
Nathan Fisher
A: 

As always when having to work with Outlook object model, I recommend using the Redemption library. (It would involve COM Interop from C#, but that shouldn't be a problem.) There you should take a look to the RDO (Redemption Data Objects) library, and there to the RDOAddressBook and RDOAddressEntry objects. The RDOAddressEntry object exposes all properties you are looking for.

The Redemption library circumvents the problems related to Outlook security and also allows access to more properties than you get exposed in the normal OOM. Unfortunately I can't provide you a working sample to solve your specific problem, as I'm using the library just for mail handling yet. But, there are plenty of code examples on the Redemption site.

MicSim