473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Session.AddressBook doesnt find my address lists.

Hello. I am writing a C# program that uses CDO 1.21 to access the outlook addressbook as a contact management system

The following code gives me the correct dialog box, but the "Show Names from the:" drop down list box is empty

I opened the correct default profile (i have only 1 profile) and I should see Global Address List (from the exchange server), and at least 1 Contact folder

try

Object[] argsAddressBook = new Object[9]
argsAddressBook[0] = Missing.Value
argsAddressBook[1] = Missing.Value
argsAddressBook[2] = Missing.Value
argsAddressBook[3] = Missing.Value
argsAddressBook[4] = Missing.Value
argsAddressBook[5] = Missing.Value
argsAddressBook[6] = Missing.Value
argsAddressBook[7] = Missing.Value
argsAddressBook[8] = Missing.Value

MAPI.Session oSession = new MAPI.Session()

argsLogon[0] = Missing.Value; // ProfileNam
argsLogon[1] = Missing.Value; // ProfilePasswor
argsLogon[2] = Missing.Value; // ShowDialo
argsLogon[3] = Missing.Value; // NewSessio
argsLogon[4] = Missing.Value; // ParentWindo
argsLogon[5] = Missing.Value; // NoMai
argsLogon[6] = Missing.Value; // ProfileInf
oSession.GetType().InvokeMember("Logon", BindingFlags.InvokeMethod, null, oSession, argsLogon)

MAPI.Recipients oRecipients
(MAPI.Recipients)oSession.GetType().InvokeMember(" AddressBook", BindingFlags.Default |BindingFlags.GetProperty, null, oSession, argsAddressBook)

The last statement brings up the correct dialog box, but it doesnt let me choose any address lists from the drop down list box

Other techniques, such as Outlook Object Model can find my folders, but its too slow so I want to do it with CDO

I know CDO 1.21 is "unsupported" with .net and c#, but is there anything obvious I have forgotten or any other way to access the AddressBooks

If I use Session.GetFolder with the correct EntryID, I can get my Contacts folder and other folders directly, and I guess I could make my own dialog box and iterate through the addresses with Folder.Messages, but I would prefer to use the builtin GUI

Thanks a lot for any tips

Kurt
Nov 15 '05 #1
6 2081
Try this:

Russell Mangel
Las Vegas, NV

// This routine, will loop through all AddressLists/AddressEntries
MAPI.SessionClass oSession = new MAPI.SessionClass();
oSession.Logon(System.Environment.UserName,
System.Reflection.Missing.Value, true, true,
System.Reflection.Missing.Value, false, System.Reflection.Missing.Value);

MAPI.AddressLists oAddressLists =
(MAPI.AddressLists)oSession.AddressLists;

for(int i = 1; i <= (int)oAddressLists.Count; i++)
{
// There can be several address lists, get first
MAPI.AddressList oAddressList =
(MAPI.AddressList)oAddressLists.get_Item(i);
// Print out each AddressList name
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);
// Print out each AddressEntry name
Console.WriteLine(" " + oAddressEntry.Name);
}
}

// End Code
Nov 15 '05 #2
Heres an example that selects one addresslist, instead of looping through
all of them:

Russell Mangel
Las Vegas, NV

// This routine, will allow you to select one AddressList

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

// You can select one AddressList, by changing the last enumerated type
MAPI.AddressList oAddressList =
(MAPI.AddressList)oSession.GetAddressList(MAPI.Cdo AddressListTypes.CdoAddres
sListPAB);

// If you are connected to Exchange Server, you can use Global Address
List
// MAPI.AddressList oAddressList =
(MAPI.AddressList)oSession.GetAddressList(MAPI.Cdo AddressListTypes.CdoAddres
sListGAL);
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);
// Print out each AddressEntry name
Console.WriteLine(" " + oAddressEntry.Name);
}
Nov 15 '05 #3
One more example for displaying Dialog box for Recipients

Russell Mangel
Las Vegas, NV

// This routine will display dialog box, for you to select Recipient.
MAPI.SessionClass oSession = new MAPI.SessionClass();
oSession.Logon(System.Environment.UserName,
System.Reflection.Missing.Value, true, true,
System.Reflection.Missing.Value, false, System.Reflection.Missing.Value);

MAPI.Recipients oRecipients = null;
MAPI.Recipient oRecipient = null;
MAPI.AddressEntry oAddressEntry = null;

// Display dialog box to select recipient(s)
// Watch the wrapping on this next line, everything needs to be on one
line.
oRecipients =
(MAPI.Recipients)oSession.AddressBook(System.Refle ction.Missing.Value,
"Select Name", true, true, -1, "", "", "", 0);

for(int i = 1; i <= (int)oRecipients.Count; i++)
{
// Do what you need with Recipient, or AddressEntry
oRecipient = (MAPI.Recipient)oRecipients.get_Item(i);
oAddressEntry = (MAPI.AddressEntry)oRecipient.AddressEntry;

Console.WriteLine(oAddressEntry.Name);
}

oSession.Logoff();

// The following are the parameters for oSession.AddressBook() method

// 1st parameter, allows all AddressLists to be displayed
// 2nd parameter, string The Title bar text for the Dialog Box
// 3rd parameter, boolean, Allow one address to be selected at one
time.
// 4th parameter, boolean, Resolve all names
// 5th prameter, int -1 , 0, 1, 2, 3 Number of recipient list boxes to
display
// 6th parameter, string, Text for 1st button
// 7th parameter, string, Text for 2nd button
// 8th paramter, string, Text for 3rd button
// 9th parameter, int 0 = (Modal dialog box) Parent window handle
Nov 15 '05 #4
Hi Russel,

Thanks a lot for your suggestion. When I run the following code,
oAddressLists.Count = 0 and the outer loop iterates 0 times.

Additionally, if I add a oSession.Logoff() at the very end, it takes
exactly 60 seconds to timeout.

I shall now try out your other suggestions.

I am suspecting something might not be correctly set up here on my PC.

Thanks

Kurt

Russell Mangel wrote:
Try this:

Russell Mangel
Las Vegas, NV

// This routine, will loop through all AddressLists/AddressEntries
MAPI.SessionClass oSession = new MAPI.SessionClass();
oSession.Logon(System.Environment.UserName,
System.Reflection.Missing.Value, true, true,
System.Reflection.Missing.Value, false, System.Reflection.Missing.Value);

MAPI.AddressLists oAddressLists =
(MAPI.AddressLists)oSession.AddressLists;

for(int i = 1; i <= (int)oAddressLists.Count; i++)
{
// There can be several address lists, get first
MAPI.AddressList oAddressList =
(MAPI.AddressList)oAddressLists.get_Item(i);
// Print out each AddressList name
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);
// Print out each AddressEntry name
Console.WriteLine(" " + oAddressEntry.Name);
}
}

// End Code

Nov 15 '05 #5
Thanks Russel.

I tried 3 different values of AddressListType in the GetAddressList call.

CdoAddressListPAB and GAL both cause an exception with error code E_FAIL.

If I try CdoAddressListTotal I get an exception with error code
E_INVALIDARG.

Strange. This is all on XP professional with latest service packs and
updates, office 2003 with all updates, visual studio 2003 .net. My test
folders reside on a windows 2000 server with exchange 2000 on it.
Outlook etc seems to work fine.

Ok a few more things to check...

Thanks

Kurt

Russell Mangel wrote:
Heres an example that selects one addresslist, instead of looping through
all of them:

Russell Mangel
Las Vegas, NV

// This routine, will allow you to select one AddressList

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

// You can select one AddressList, by changing the last enumerated type
MAPI.AddressList oAddressList =
(MAPI.AddressList)oSession.GetAddressList(MAPI.Cdo AddressListTypes.CdoAddres
sListPAB);

// If you are connected to Exchange Server, you can use Global Address
List
// MAPI.AddressList oAddressList =
(MAPI.AddressList)oSession.GetAddressList(MAPI.Cdo AddressListTypes.CdoAddres
sListGAL);
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);
// Print out each AddressEntry name
Console.WriteLine(" " + oAddressEntry.Name);
}

Nov 15 '05 #6
Hmmm

Thanks Russell

But I get the same problem as I had before.

The AddressBook dialog box appears, but the drop down list box contains
no address lists :-(

Additionally, the logoff takes exactly 60 seconds. In other examples it
takes exactly 120 seconds which makes me think there is some minute long
timeout value specified somewhere....

I might have to try this program on another machine.

Thanks a lot,

Kurt

Russell Mangel wrote:
One more example for displaying Dialog box for Recipients

Russell Mangel
Las Vegas, NV

// This routine will display dialog box, for you to select Recipient.
MAPI.SessionClass oSession = new MAPI.SessionClass();
oSession.Logon(System.Environment.UserName,
System.Reflection.Missing.Value, true, true,
System.Reflection.Missing.Value, false, System.Reflection.Missing.Value);

MAPI.Recipients oRecipients = null;
MAPI.Recipient oRecipient = null;
MAPI.AddressEntry oAddressEntry = null;

// Display dialog box to select recipient(s)
// Watch the wrapping on this next line, everything needs to be on one
line.
oRecipients =
(MAPI.Recipients)oSession.AddressBook(System.Refle ction.Missing.Value,
"Select Name", true, true, -1, "", "", "", 0);

for(int i = 1; i <= (int)oRecipients.Count; i++)
{
// Do what you need with Recipient, or AddressEntry
oRecipient = (MAPI.Recipient)oRecipients.get_Item(i);
oAddressEntry = (MAPI.AddressEntry)oRecipient.AddressEntry;

Console.WriteLine(oAddressEntry.Name);
}

oSession.Logoff();

// The following are the parameters for oSession.AddressBook() method

// 1st parameter, allows all AddressLists to be displayed
// 2nd parameter, string The Title bar text for the Dialog Box
// 3rd parameter, boolean, Allow one address to be selected at one
time.
// 4th parameter, boolean, Resolve all names
// 5th prameter, int -1 , 0, 1, 2, 3 Number of recipient list boxes to
display
// 6th parameter, string, Text for 1st button
// 7th parameter, string, Text for 2nd button
// 8th paramter, string, Text for 3rd button
// 9th parameter, int 0 = (Modal dialog box) Parent window handle

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: ZoombyWoof | last post by:
Hi. Im very new to php, and I have a problem here that I cant find the solution for. I have problems with session variables, I want some variables to maintain their value between different php...
27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
6
by: Kurt | last post by:
Hello. I am writing a C# program that uses CDO 1.21 to access the outlook addressbook as a contact management system The following code gives me the correct dialog box, but the "Show Names from...
1
by: Lauren Quantrell | last post by:
I know if I was using an Access MDB I could link to MS Outlook folders and the addressbook. But I'm using an Access Project (ADP) and want to figure out a way to link to the Outlook addressbook...
0
by: Czar Eclarinal | last post by:
Hi Everyone, I've declared a datatable out of my typed dataset stored in session and add a new row to it. When state management is set to InProc and I modified the declared dataable, the changes...
6
by: Fabian Braennstroem | last post by:
Hi, I want to get access to my abook address file with python. Does anyone have some python lines to achive this using curses? If not, maybe anybody has small python program doing it with a...
10
by: OppThumb | last post by:
Hi, I've been searching this newsgroup for an answer to my question, and the closest I've come asks my question, but in reverse ("How to figure out the program from plan/package"). I've -- shall...
9
by: Markus | last post by:
Hi In cases where I need to store the session id and/or the remote host in a database I used to choose tinytext fields so far. Anyway the usual values for session ids are of 32 characters...
0
by: Gnana | last post by:
Following is the piece of code i got from this forum itself but stil i am not able to get the full details of recepients like location,office number. plz help me to access that information.. ...
11
by: mishrarajesh44 | last post by:
i am facing problem in php session.. my code is giving error.. i am giving my code and error message below.. my code:- <?php if(isset($_POST)) { if(empty($password)){echo "No...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.