473,383 Members | 1,739 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,383 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
Jul 21 '05 #1
6 2170
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
Jul 21 '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);
}
Jul 21 '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
Jul 21 '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

Jul 21 '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);
}

Jul 21 '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

Jul 21 '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...
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...
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...
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...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.