Get Outlook contacts into C# form-based application

前端 未结 4 727
温柔的废话
温柔的废话 2020-12-06 19:29

I have tried to get the contacts of Outlook contacts into C#, but it is not working. I have used the Microsoft Outlook 12.0 Object Library. I want to show the data in richte

4条回答
  •  醉话见心
    2020-12-06 20:16

    This code is working fine in my C#-Solution.

    using Outlook =Microsoft.Office.Interop.Outlook;
    
    private void kontaktImport_Click(object sender, RoutedEventArgs e)
            {
                Outlook.Application app = new Outlook.Application();
                Outlook.NameSpace NameSpace = app.GetNamespace("MAPI");
                Outlook.MAPIFolder ContactsFolder = NameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
                Outlook.Items ContactItems = ContactsFolder.Items;
                try
                {
                    foreach (Outlook.ContactItem item in ContactItems)
                    {
                        String output = "";
                        output = item.FirstName + "\n";
                        output += item.LastName;
                        TestTextBox.Text = output;
                    }
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    TestTextBox.Text = ex.ToString();
                }
            }         
    

提交回复
热议问题