Click to See Complete Forum and Search --> : Access outlook contacts from C#
Nightfall
November 26th, 2004, 05:30 PM
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!
Sahir
November 27th, 2004, 09:05 AM
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
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.
Nightfall
November 27th, 2004, 09:22 AM
Thanks a lot! :thumb:
SanjaySL
October 20th, 2005, 06:50 AM
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
boudino
October 21st, 2005, 03:09 AM
This should work
ctc = (Outlook.ContactItem) ctcItems[j]
And be sure you working with rightversion of Microsoft Outlook 10.0 Object Library.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.