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!
Printable View
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!
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
This will add the full name from each contact item to the list box.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());
}
}
Thanks a lot! :thumb:
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
This should work
And be sure you working with rightversion of Microsoft Outlook 10.0 Object Library.Code:ctc = (Outlook.ContactItem) ctcItems[j]