Get Outlook contacts into C# form-based application

前端 未结 4 713
温柔的废话
温柔的废话 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:27

    This works for me. It gets all the contacts from outlook and shows it in datagridview.

      Microsoft.Office.Interop.Outlook.Items OutlookItems;
      Microsoft.Office.Interop.Outlook.Application outlookObj = new Microsoft.Office.Interop.Outlook.Application();
      MAPIFolder Folder_Contacts;
      Folder_Contacts = (MAPIFolder)outlookObj.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
      OutlookItems = Folder_Contacts.Items;
      MessageBox.Show("Wykryto kontaktów: " + OutlookItems.Count.ToString());
    
      for (int i = 0; i < OutlookItems.Count; i++)
      {
        Microsoft.Office.Interop.Outlook.ContactItem contact = (Microsoft.Office.Interop.Outlook.ContactItem)OutlookItems[i+1];
        sNazwa = contact.FullName;
        sFirma = contact.CompanyName;
        sAdress = contact.BusinessAddressStreet;
        sMiejscowosc = contact.BusinessAddressPostalCode + " " + contact.BusinessAddressCity;
        sEmail = contact.Email1Address;
        dataGridView1.Rows.Add(sNazwa, sFirma, sAdress, sMiejscowosc, sEmail);
    
      }
    

提交回复
热议问题