Pragmatically access Outlook Contacts

VSTO

Below is the code to access contact from Outlook progmatically:


    Outlook.MAPIFolder folderContacts = this.Application.ActiveExplorer().Session.

   GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

   Outlook.Items searchFolder = folderContacts.Items;

   int counter = 0;

   foreach (Outlook.ContactItem foundContact in searchFolder)

   {

      if (foundContact.LastName.Contains(findLastName))

      {

         foundContact.Display(false);

         counter = counter + 1;

      }

    }

    MessageBox.Show("You have " + counter +  " contacts with last names that contain " + findLastName + ".");


Aspose.Email

The MapiContact class can be used to load both Outlook MSG and VCard format contacts. The following code samples show how to load Outlook contacts saved as MSG and VCF into a MapiContact.


     var vcfTest = VCardContact.Load("Jon.vcf");

    MapiContact contact = MapiContact.FromVCard(@"E:\Aspose\Aspose Vs VSTO\Aspose.Emails Vs VSTO Outlook v 1.1\Sample Files\Jon.vcf");

    Console.WriteLine(contact.NameInfo.DisplayName);


Download Sample Code

Download Running Code