title: Programmatically Search for a Specific Contact in Outlook using WinForm
body: <p>I found this code <a href="https://msdn.microsoft.com/en-us/library/ms269001.aspx" rel="nofollow noreferrer">here</a> to search for Outlook contacts using C# winform. I'm having a hard time understanding why the code is not working as is. VS2015 is telling me "'Myapp' does not contain a definition for 'Application' and no extension method 'Application' accepting a first argument of type 'Myapp' could be found (are you missing a using directive or an assembly reference?)"</p>
  
  <p>Here is the code:</p>
  
  <pre><code> private void FindContactEmailByName(string firstName, string lastName)
      {
          Outlook.NameSpace outlookNameSpace = this.Application.GetNamespace("MAPI"); //VS does not like this line, particularly "Application"
          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;
          }
      }
  </code></pre>