Hi all I'm using trying to get my app to read in all contacts in the
contact folder of Outlook. I'm using the Outlook Security manager to
stop the pop up warnings. Outlook version is 2002(10.2627.2625) I can
create a contact in Outlook and I can use it to send an email. It's
just the getting the contacts list that doesn't work. The thing is it
also works on my dev machine but not on the users machine.
The code I'm using:
SecurityManager = new AddinExpress.Outlook.SecurityManager();
Outlook._Application outlookObj = new Outlook.Application();
Outlook.MAPIFolder fldContacts =
Outlook.Items searchFolder = fldContacts.Items;
Outlook.ContactItem contactItem = (Outlook.ContactItem)searchFolder.GetFirst();
//Code to create a data table to put the contact info into.
dv = new DataView(dt);
dv.Sort = "First Name ASC";
dgContacts.DataSource = dv;
catch (Exception ex)
MessageBox.Show("Contact List could not be retrieved from Outlook", "Contacts not retrieved",
SecurityManager.DisableOOMWarnings = false;
Can anyone see anything wrong here I for the life of me can't figure
out what is going on. I thought that the problem was with different
versions of Outlook, but they are the same. Oh and I'm not using the
enumeration for the Contacts Folder because Outlook 2002 doesn't
support it. If I tried to use this code on Outlook 2003 would it work
Hmmmm did a bit more digging it's failing on the cast: contactItem = (Outlook.ContactItem)searchFolder.GetNext(); in the while loop.
The error is: System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type "Outlook.ContactItem".
This is because he has a distribution list in his contacts folder and I have none. So I guess if anyone else is trying to do this same sort of operation watch out for distribution lists and ignore them if they come up.
Posted: Visual C# General, C# - Can't get list of outlook contacts on some machines