Get Contacts from Outlook 2007 in C#?

  • Thread starter Thread starter Volkan Senguel
  • Start date Start date
V

Volkan Senguel

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
 
I founded a way how to get this, here is it at a demo app:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;

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

private void getContacts_Click(object sender, EventArgs e)
{
// Obtain an instance of the Outlook application
Outlook.Application app = new Outlook.ApplicationClass();

// 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);

// Iterate through each contact
for (int i = 1; i < contacts.Items.Count + 1; i++)
{
// Get a contact
Outlook.ContactItem contact =
(Outlook.ContactItem)contacts.Items;
txtResults.Text += contact.FullName + " (" +
contact.BusinessTelephoneNumber + ")" + Environment.NewLine;
Application.DoEvents();
}
}
}
}


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

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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;

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

private void getContacts_Click(object sender, EventArgs e)
{
// Obtain an instance of the Outlook application
Outlook.Application app = new Outlook.ApplicationClass();

// 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);

// Iterate through each contact
for (int i = 1; i < contacts.Items.Count + 1; i++)
{
// Get a contact
Outlook.ContactItem contact =
(Outlook.ContactItem)contacts.Items;
txtResults.Text += contact.FullName + " (" +
contact.BusinessTelephoneNumber + ")" + Environment.NewLine;
Application.DoEvents();
}
}
}
}


thx
Volkan
Volkan Senguel said:
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
 
Its a Winform project, and the only refference is the
Microsoft.Office.Interop.Outlook (Microsoft Outlook 12.0 Object Library)
com object.

Yes it works flawless ;)

greets
Volkan

Berryl Hesh said:
What kind of project did you make that in? What references did you add to
make it work?

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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;

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

private void getContacts_Click(object sender, EventArgs e)
{
// Obtain an instance of the Outlook application
Outlook.Application app = new Outlook.ApplicationClass();

// 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);

// Iterate through each contact
for (int i = 1; i < contacts.Items.Count + 1; i++)
{
// Get a contact
Outlook.ContactItem contact =
(Outlook.ContactItem)contacts.Items;
txtResults.Text += contact.FullName + " (" +
contact.BusinessTelephoneNumber + ")" + Environment.NewLine;
Application.DoEvents();
}
}
}
}


thx
Volkan
Volkan Senguel said:
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

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top