开发者

using the outlook object model, can i get the fields that i see in the outlook contact

i am able to look through the global address book using the outlook object model b开发者_开发知识库ut 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


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();
    }
}


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

RDO & C#


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜