M
Marketware
I need to iterate through all of the contacts in a contact folder. I have
tried two methods to get the contacts out of a Contact folder: Here is the
first code I've tried:
Outlook.Application Outlook = new Outlook.Application();
Outlook.MAPIFolder fldContacts =
(Outlook.MAPIFolder)Outlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
foreach (Outlook.ContactItem oItem1 in fldContacts.Items)
{//Get each contact...}
I get the following complile error when I attempt the above:
foreach statement cannot operate on variables of type 'Outlook.Items'
because 'Outlook.Items' does not contain a public definition for
'GetEnumerator'
Then I tried this approach:
Outlook.ContactItem oItem;
for (int j = 0; j < oContactFolder.Items.Count; j++)
{
if (j == 0)
oItem = (Outlook.ContactItem)oContactFolder.Items.GetFirst();
else
oItem = (Outlook.ContactItem)oContactFolder.Items.GetNext();
But with the above approach I'm getting the first contact, and a second, but
from that point on it keeps returning the same second record (out of 20
total).
Can anyone help me see what I am doing wrong here? It really shouldn't be
that difficult to accomplish what I am trying to do here.
Thanks!!!!!!!!!
bob
tried two methods to get the contacts out of a Contact folder: Here is the
first code I've tried:
Outlook.Application Outlook = new Outlook.Application();
Outlook.MAPIFolder fldContacts =
(Outlook.MAPIFolder)Outlook.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
foreach (Outlook.ContactItem oItem1 in fldContacts.Items)
{//Get each contact...}
I get the following complile error when I attempt the above:
foreach statement cannot operate on variables of type 'Outlook.Items'
because 'Outlook.Items' does not contain a public definition for
'GetEnumerator'
Then I tried this approach:
Outlook.ContactItem oItem;
for (int j = 0; j < oContactFolder.Items.Count; j++)
{
if (j == 0)
oItem = (Outlook.ContactItem)oContactFolder.Items.GetFirst();
else
oItem = (Outlook.ContactItem)oContactFolder.Items.GetNext();
But with the above approach I'm getting the first contact, and a second, but
from that point on it keeps returning the same second record (out of 20
total).
Can anyone help me see what I am doing wrong here? It really shouldn't be
that difficult to accomplish what I am trying to do here.
Thanks!!!!!!!!!
bob