CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    45

    Access outlook contacts from C#

    Hi

    I want to get phonenumbers from my outlook contacts. Anyone have any idea how to do this in C#? If you have any tips at all, plz post... I am really stuck here.

    Thanks in advance!

  2. #2
    Join Date
    Aug 2002
    Location
    Kerala
    Posts
    1,183

    Re: Access outlook contacts from C#

    Here is a sample. Create a new Windows Forms project. Add a list box and a button to the form. From menubar select Project|Add Reference. Select the COM tab and add a reference to Microsoft Outlook 10.0 Object Library.

    Now add the following code

    Code:
     private void button2_Click(object sender, System.EventArgs e) {
          Outlook._Application outlook = new Outlook.ApplicationClass();
          Outlook.NameSpace ns = outlook.GetNamespace("MAPI");
         
          Outlook.MAPIFolder cf  =  ns.GetDefaultFolder 
                                                  (Outlook.OlDefaultFolders.olFolderContacts);
          Outlook.Items ctcItems =  cf.Items;
          Outlook.ContactItem ctc;
          for(int j = 1; j < (ctcItems.Count + 1); j++) { 
             ctc = (Outlook.ContactItem) ctcItems.Item(j);
             list1.Items.Add(ctc.FullName.ToString());
          } 
      }
    This will add the full name from each contact item to the list box.
    Last edited by Sahir; November 27th, 2004 at 10:11 AM.

  3. #3
    Join Date
    Mar 2004
    Posts
    45

    Re: Access outlook contacts from C#

    Thanks a lot!

  4. #4
    Join Date
    Oct 2005
    Posts
    1

    Re: Access outlook contacts from C#

    Hi ,

    I tried that coding u have poested here.But there is an error.

    ctc = (Outlook.ContactItem) ctcItems.Items(j);

    There is no Items method in ctcItems.What shall I do?

    ***BTW I was searching thw net to find "How to access outlook contacts from C# n this answer given by u is the one n only in the net.

    Regards

  5. #5
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Access outlook contacts from C#

    This should work
    Code:
    ctc = (Outlook.ContactItem) ctcItems[j]
    And be sure you working with rightversion of Microsoft Outlook 10.0 Object Library.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured