Get Contacts from Outlook 2007 in C#?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Volkan Senguel

    Get Contacts from Outlook 2007 in C#?

    Hi
    Is there a easy way to get the contacts (names and phonenumbers) from
    outlook without the message that someone is accessing outlook and how long
    the access can take?

    i have not found any working solution for that :(

    thanks for any help
    Volkan


  • Volkan Senguel

    #2
    Re: Get Contacts from Outlook 2007 in C#?

    I founded a way how to get this, here is it at a demo app:

    using System;
    using System.Collecti ons.Generic;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows. Forms;
    using Outlook = Microsoft.Offic e.Interop.Outlo ok;

    namespace Contacter
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeCompo nent();
    }

    private void getContacts_Cli ck(object sender, EventArgs e)
    {
    // Obtain an instance of the Outlook application
    Outlook.Applica tion app = new Outlook.Applica tionClass();

    // Access the MAPI namespace
    Outlook.NameSpa ce ns = app.GetNamespac e("MAPI");

    // Get the user's default contacts folder
    Outlook.MAPIFol der contacts =
    ns.GetDefaultFo lder(Outlook.Ol DefaultFolders. olFolderContact s);

    // Iterate through each contact
    for (int i = 1; i < contacts.Items. Count + 1; i++)
    {
    // Get a contact
    Outlook.Contact Item contact =
    (Outlook.Contac tItem)contacts. Items[i];
    txtResults.Text += contact.FullNam e + " (" +
    contact.Busines sTelephoneNumbe r + ")" + Environment.New Line;
    Application.DoE vents();
    }
    }
    }
    }


    thx
    Volkan
    "Volkan Senguel" <morpheus@2wire .chschrieb im Newsbeitrag
    news:OUKAmo0HJH A.2272@TK2MSFTN GP04.phx.gbl...
    Hi
    Is there a easy way to get the contacts (names and phonenumbers) from
    outlook without the message that someone is accessing outlook and how long
    the access can take?
    >
    i have not found any working solution for that :(
    >
    thanks for any help
    Volkan
    >
    >

    Comment

    • Berryl Hesh

      #3
      Re: Get Contacts from Outlook 2007 in C#?

      What kind of project did you make that in? What references did you add to
      make it work?

      "Volkan Senguel" <morpheus@2wire .chwrote in message
      news:uXEaft0HJH A.4408@TK2MSFTN GP06.phx.gbl...
      >I founded a way how to get this, here is it at a demo app:
      >
      using System;
      using System.Collecti ons.Generic;
      using System.Componen tModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows. Forms;
      using Outlook = Microsoft.Offic e.Interop.Outlo ok;
      >
      namespace Contacter
      {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeCompo nent();
      }
      >
      private void getContacts_Cli ck(object sender, EventArgs e)
      {
      // Obtain an instance of the Outlook application
      Outlook.Applica tion app = new Outlook.Applica tionClass();
      >
      // Access the MAPI namespace
      Outlook.NameSpa ce ns = app.GetNamespac e("MAPI");
      >
      // Get the user's default contacts folder
      Outlook.MAPIFol der contacts =
      ns.GetDefaultFo lder(Outlook.Ol DefaultFolders. olFolderContact s);
      >
      // Iterate through each contact
      for (int i = 1; i < contacts.Items. Count + 1; i++)
      {
      // Get a contact
      Outlook.Contact Item contact =
      (Outlook.Contac tItem)contacts. Items[i];
      txtResults.Text += contact.FullNam e + " (" +
      contact.Busines sTelephoneNumbe r + ")" + Environment.New Line;
      Application.DoE vents();
      }
      }
      }
      }
      >
      >
      thx
      Volkan
      "Volkan Senguel" <morpheus@2wire .chschrieb im Newsbeitrag
      news:OUKAmo0HJH A.2272@TK2MSFTN GP04.phx.gbl...
      >Hi
      >Is there a easy way to get the contacts (names and phonenumbers) from
      >outlook without the message that someone is accessing outlook and how
      >long the access can take?
      >>
      >i have not found any working solution for that :(
      >>
      >thanks for any help
      >Volkan
      >>
      >>
      >
      >

      Comment

      • Volkan Senguel

        #4
        Re: Get Contacts from Outlook 2007 in C#?

        Its a Winform project, and the only refference is the
        Microsoft.Offic e.Interop.Outlo ok (Microsoft Outlook 12.0 Object Library)
        com object.

        Yes it works flawless ;)

        greets
        Volkan

        "Berryl Hesh" <efinger9@yahoo .comschrieb im Newsbeitrag
        news:JFTCk.3287 2$rV4.24401@new sfe03.iad...
        What kind of project did you make that in? What references did you add to
        make it work?
        >
        "Volkan Senguel" <morpheus@2wire .chwrote in message
        news:uXEaft0HJH A.4408@TK2MSFTN GP06.phx.gbl...
        >>I founded a way how to get this, here is it at a demo app:
        >>
        >using System;
        >using System.Collecti ons.Generic;
        >using System.Componen tModel;
        >using System.Data;
        >using System.Drawing;
        >using System.Linq;
        >using System.Text;
        >using System.Windows. Forms;
        >using Outlook = Microsoft.Offic e.Interop.Outlo ok;
        >>
        >namespace Contacter
        >{
        > public partial class Form1 : Form
        > {
        > public Form1()
        > {
        > InitializeCompo nent();
        > }
        >>
        > private void getContacts_Cli ck(object sender, EventArgs e)
        > {
        > // Obtain an instance of the Outlook application
        > Outlook.Applica tion app = new Outlook.Applica tionClass();
        >>
        > // Access the MAPI namespace
        > Outlook.NameSpa ce ns = app.GetNamespac e("MAPI");
        >>
        > // Get the user's default contacts folder
        > Outlook.MAPIFol der contacts =
        >ns.GetDefaultF older(Outlook.O lDefaultFolders .olFolderContac ts);
        >>
        > // Iterate through each contact
        > for (int i = 1; i < contacts.Items. Count + 1; i++)
        > {
        > // Get a contact
        > Outlook.Contact Item contact =
        >(Outlook.Conta ctItem)contacts .Items[i];
        > txtResults.Text += contact.FullNam e + " (" +
        >contact.Busine ssTelephoneNumb er + ")" + Environment.New Line;
        > Application.DoE vents();
        > }
        > }
        > }
        >}
        >>
        >>
        >thx
        >Volkan
        >"Volkan Senguel" <morpheus@2wire .chschrieb im Newsbeitrag
        >news:OUKAmo0HJ HA.2272@TK2MSFT NGP04.phx.gbl.. .
        >>Hi
        >>Is there a easy way to get the contacts (names and phonenumbers) from
        >>outlook without the message that someone is accessing outlook and how
        >>long the access can take?
        >>>
        >>i have not found any working solution for that :(
        >>>
        >>thanks for any help
        >>Volkan
        >>>
        >>>
        >>
        >>
        >
        >
        >

        Comment

        Working...