use the below code to find the outlook contact by firstname and lastname in c#
all the best
private void ThisApplication_Startup(object sender, System.EventArgs e)
{
FindContactEmailByName("Sateesh", "kumar");
}
private void FindContactEmailByName(string firstName, string lastName)
{
Outlook.NameSpace outlookNameSpace = this.GetNamespace("MAPI");
Outlook.MAPIFolder contactsFolder =
outlookNameSpace.GetDefaultFolder(
Microsoft.Office.Interop.Outlook.
OlDefaultFolders.olFolderContacts);
Outlook.Items contactItems = contactsFolder.Items;
try
{
Outlook.ContactItem contact =
(Outlook.ContactItem)contactItems.
Find(String.Format("[FirstName]='{0}' and "
+ "[LastName]='{1}'", firstName, lastName));
if (contact != null)
{
contact.Display(true);
}
else
{
MessageBox.Show("The contact information was not found");
}
}
catch (Exception ex)
{
throw ex;
}
}
No comments:
Post a Comment