C# - Get all Outlook Contacts

By , 2/14/2009
(1 ratings)
This function allows you, to read out all saved contacts from Microsoft Outlook. To run this console application, you have to add two references to your project:

- right click to your project
- select the com tab
- add Microsoft Office 12.0 Object Library and Microsoft Outlook 12.0 Object Library

If you use Outlook 2003 choose version 11.
Translate to VB
using System;
using Microsoft.Office.Interop.Outlook;

namespace GetContacts
{
    internal class Program
    {
        private static void Main()
        {
            var outlookApplication = new ApplicationClass();
            NameSpace mapiNamespace = outlookApplication.GetNamespace("MAPI");
            MAPIFolder contacts = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderContacts);

            for (int i = 1; i < contacts.Items.Count + 1; i++)
            {
                var contact = (ContactItem) contacts.Items[i];
                Console.WriteLine(contact.FullName);
                Console.WriteLine(contact.Email1Address);
                Console.WriteLine();
            }
            Console.Read();
        }
    }
}

Comments

 

Log in, to comment!