I'm using MSOUTL.OLB from Office 11.
I'm getting an System.InvalidCastException error with the following code.
It looks like it is thrown at the end of the contact name list. Names are
displayed in the ListBox. Here is the code I'm using. Would it be better
to use "for" rather than the "foreach"? If so, the oCt =
(Outlook.ContactItem)oItems.Item(i); line doesn't accept oItems.Item.....
Outlook.Application objOutlook = new Outlook.Application();
Outlook.NameSpace objNS = objOutlook.GetNamespace("MAPI");
objNS.Logon ("","",false,true);
Outlook.MAPIFolder cContacts =
objNS.GetDefaultFolder(Outlook.OlDefaultFolders.ol FolderContacts);
Outlook.Items oItems= cContacts.Items;
//Outlook.ContactItem oCt ;
int numItems;
numItems = cContacts.Items.Count;
//for (int i=1; i != numItems-1; i++)
foreach(Outlook.ContactItem cim in oItems)
{
//oCt = (Outlook.ContactItem)oItems.Item(i);
// Add Contacts Full Name to ListBox
outlookListBox.Items.Add(cim.FullName.ToString());
Application.DoEvents();
}
objNS.Logoff();
TIA,
--
Fritz