dotnet-Snippets.com
Snippets: 61 | Registered User: 61 | Visitors online: 10
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Get all Outlook Contacts

Author: Jan Welker
Programming Language: C# Rating:
not yet rated

Views: 1527

Description:

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.




C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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();
        }
    }
}


This Snippets could be interesting for you:
No results available

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to wrtite an comment.)