A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Iterating a Contacts folder for Outlook 2003 and 2007 in C#



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old March 22nd 10, 04:35 PM posted to microsoft.public.outlook.program_vba
Marketware
external usenet poster
 
Posts: 6
Default Iterating a Contacts folder for Outlook 2003 and 2007 in C#

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.GetDefaultFold er(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
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2003 - CONTACTS - Unable to display folder folder is full Pearson385 Outlook - Using Contacts 7 September 5th 09 02:22 PM
Import contacts from Vista contact folder to outlook 2003 contacts bikeguy55 Outlook - Using Contacts 1 February 4th 09 05:51 PM
How to convert 2003 personal folder contacts to Outlook 2007 Carol Outlook - Using Contacts 2 October 25th 07 03:57 PM
Type Mismatch when iterating through eMail-folder MailItems in Outlook 2003 [email protected] Outlook and VBA 3 October 5th 07 02:45 PM
How to share outlook 2003 customize contacts or contacts subfolder without do it on public folder? Sue Mosher [MVP-Outlook] Outlook - Using Contacts 4 June 28th 07 10:45 PM


All times are GMT +1. The time now is 12:53 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.