Hello,
Above is the exception that I receive when I want to open a new MAPI session, to retreive the global address book from the exchange server. I am building an Outlook add-in, the version used is 2003
I tried to add [STAThread] to the methods used, but this had no effect. What could this be?
Thanks in advance.
Sjakie
---------------------------------------------
Yes, the world is full of strange people.
Above is the exception that I receive when I want to open a new MAPI session, to retreive the global address book from the exchange server. I am building an Outlook add-in, the version used is 2003
I tried to add [STAThread] to the methods used, but this had no effect. What could this be?
Thanks in advance.
Sjakie
Code:
try {
MAPI.SessionClass oSession = new MAPI.SessionClass(); //session
oSession.Logon(System.Environment.UserName, System.Reflection.Missing.Value, false, false, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value); //login
// You can select one AddressList,
// by changing the last enumerated type
// selecting global addres list
// MAPI.AddressList oAddressList = (MAPI.AddressList) oSession.GetAddressList(MAPI.CdoAddressListTypes.CdoAddressListPAB);
MAPI.AddressList oAddressList = (MAPI.AddressList) oSession.GetAddressList(MAPI.CdoAddressListTypes.CdoAddressListGAL);
System.Diagnostics.Debug.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
System.Diagnostics.Debug.WriteLine(" " + oAddressEntry.Name);
}
oSession.Logoff();
}
catch (System.Exception ex) {
System.Diagnostics.Debug.WriteLine(ex.Message);
System.Diagnostics.Debug.WriteLine(ex.StackTrace);
System.Diagnostics.Debug.WriteLine(ex.Source);
}
---------------------------------------------
Yes, the world is full of strange people.