Topaz Filer - Email filing software
CDO 1.21 AddressEntry.Fields
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Mike
Hello,

I am trying to read information from the GAL using C# .NET. I am able to return a list of all the addresses and names, however, when I walk through each address I cannot access the MAPI.AddressEntry.Fields(proptag) property. VS .NET will not allow the code to compile. I am looking to pull out more info than just the addresses and names. My environment consists of the following:

CDO 1.21
Exchange 5.5
Outlook 2002
VS .NET 2003

Here is the code:

MAPI.SessionClass oSession = new MAPI.SessionClass();
oSession.Logon("OUTLOOK", System.Reflection.Missing.Value, true, true, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value);

MAPI.AddressList oAddressList = (MAPI.AddressList) oSession.GetAddressList(MAPI.CdoAddressListTypes.CdoAddressListGAL);
Console.WriteLine(oAddressList.Name);
MAPI.AddressEntries oAddressEntries = (MAPI.AddressEntries)oAddressList.AddressEntries;

    for(int j = 1; j <= (int)oAddressEntries.Count; j++)
    {
        MAPI.AddressEntry oAddressEntry = (MAPI.AddressEntry)oAddressEntries.get_Item(j);
                
                
        if(oAddressEntry.DisplayType.Equals(0) || oAddressEntry.DisplayType.Equals(6))
        {
            Console.WriteLine(" " + oAddressEntry.Name + " " + oAddressEntry.Fields);
        }
    }

If I try oAddressEntry.Fields(proptag) the code will not compile and will return this error:
'MAPI.AddressEntry.Fields' denotes a 'property' where a 'method' was expected

Any advice is greatly appreciated.

Thanks,
Mike

Reply to this message...
Vote that this is a GOOD answer...
 
New BootFX DBGet build available
Twitter and Snow… simple #uksnow
 
    
Jay B. Harlow [MVP - Outlook] (VIP)
Mike,
Have you tried:

oAddressEntry.Fields.get_Item(proptag)

The following site provides a number of resources on using Outlook with
..NET.

http://www.microeye.com/resources/res_outlookvsnet.htm

Hope this helps
Jay

"Mike" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

each address I cannot access the MAPI.AddressEntry.Fields(proptag) property.
VS .NET will not allow the code to compile. I am looking to pull out more
info than just the addresses and names. My environment consists of the
following:
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Mike
Jay,

The get_Item method is not a member of the Fields object, at least its not an exposed member. I have explored the microeye site and cannot find anything there.

Regards,
Mike
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Jay B. Harlow [MVP - Outlook] (VIP)
Mike,
I was basing my example on your example. Your example used get_Item on
AddressEntries, hence my example used get_Item on Fields. Neither collection
has a get_Item method per se.

However! Both Fields & AddressEntries have an Item property. The point I am
trying to make is that Fields may not have an indexer, (the parametized Item
property) that is usable from C#, hence your need to use the get_Item method
directly. Also word of warning Fields.Item takes two parameters! The second
one is optional.

Remember that CDO is not supported under .NET, your mileage may vary, I find
using CDO from VB.NET to be very usable, I have not attempted from C# yet. I
am able to use the Item property from VB.NET on the Fields collection.

Hope this helps
Jay

"Mike" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

anything there.
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Mike
Jay,

Thanks for your advice - I am new to using CDO and I may end up switching this over to VB .NET.

Thanks,
Mike
Reply to this message...
Vote that this is a GOOD answer...
 
Windows 7 compatible tool for mounting ISO images
Introduction to BootFX’s Object Relational Mapping Functionality article now live on CodeProject
 
    
Robert Zander
Mike,

The get_Item() method behaves quite strangely in C#, (if you're relying on VB documentation). You only need a small adjustment to your code in order to make it work. With C#, you MUST supply two parameters to this method. The first is a defined constant that specifies the particular AddressEntry field property you desire to access. These constants are defined in MAPI.CdoPropTags.x where x denotes the particular field, (e.g. CdoPR_DISPLAY_NAME). (You can find most of the available fields by following the link http://www.cdolive.com/cdo10.htm and browsing down to the "AddressEntry properties" section). The second paramater appears to be totally ignored, (as I've passed in several datatypes, (e.g. "", -1, null), and gotten the same result). For safeties sake, I'd use null or System.Reflection.Missing.Value. I've changed the line where you write to the console so that it'll work. All of the casting convolutes it, but it's absolutely necessary in C#. Enjoy.

for(int j = 1; j <= (int)oAddressEntries.Count; j++)
{
MAPI.AddressEntry oAddressEntry = (MAPI.AddressEntry)oAddressEntries.get_Item(j);

if(oAddressEntry.DisplayType.Equals(0) || oAddressEntry.DisplayType.Equals(6))
{
Console.WriteLine(" " + oAddressEntry.Name + " " + ( (MAPI.Field) ( (MAPI.Fields) oAddressEntry.Fields).get_Item(MAPI.CdoPropTags.CdoPR_ACCOUNT,null)).Value);

}
}

--------------------------------
From: Robert Zander
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
ramy elsayed
help with the same code i need to access CDOLIstTypes.CdoAddressListPAB

exception occurs cdo 80004005

exchange server 2003 with sp1
windows server 2000 sp4
IIS
C#
windows app

The GAL is working

I want the PAB personal Address book
Help me plz.. and really great work

Thanks
Best Regards
Ramy EL Sayed
Reply to this message...
Vote that this is a GOOD answer...
 
Xenu Link Sleuth
Chromium OS – really?
 
 
System.Console
System.Reflection.Missing




Ad
BootFX
Reliable and powerful .NET application framework.
Looking to invest in a major software project? Technical and commercial advice available here.
Other Helpful Sites
MBR 247
Topaz Filer
SharePoint Email Filing
Software Advisory Services
 
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734