Hi,
Im trying to get all the contacts that I have in outlook and writing them to a textbox.
This is my code:
// Obtain an instance of the Outlook applicationMicrosoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
// Access the MAPI namespace
Outlook.NameSpace ns = app.GetNamespace("MAPI");
// Get the user's default contacts folder
Outlook.MAPIFolder contacts = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
// Go through all the folders
foreach (Outlook.Folder folder in contacts.Folders)
{
// Iterate through each contact
for (int i = 1; i < folder.Items.Count + 1; i++)
{
// Get a contact
Outlook.ContactItem contact = (Outlook.ContactItem)folder.Items[i];
// Write contact info to textbox
richTextBox1.Text += folder.AddressBookName.ToString() + " " + contact.EntryID + " " + Environment.NewLine;
}
}
But I only get the contacts in the first folder, where am I going wrong?

Shakti Singh DulawatRank #668 · 3.6K reputationPosted May 5, 2016, 8:06 PM EDT
Carl-Johan Larsson15 reputationPosted May 5, 2016, 11:34 PM EDT
Shakti Singh DulawatRank #668 · 3.6K reputationPosted May 6, 2016, 12:01 AM EDT