Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Cannot open 2 or more outlook contact detail

Cannot open 2 or more outlook contact detail

Scheduled Pinned Locked Moved C#
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manfree
    wrote on last edited by
    #1

    Hi all, The following code can popup a particular Outlook contact detail Click button 1, it opens Tom Lee contact detail Then, close the Tom Lee contact detail Click button 2, it opens Sam Green contact detail It works fine ... However, if I am going to open both contact detail (without closing the other person contact) it will come up with an error >>> "A dialog box is open. Close it and try again" Any body knows how to solve it ?? Thanks

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    using Outlook = Microsoft.Office.Interop.Outlook;

    namespace testing1
    {
    public partial class Form1 : Form
    {
    Outlook.Application oApp = new Outlook.Application();
    string firstName;
    string lastName;

        public Form1()
        {
            InitializeComponent();
        }
    
        private void Form1\_Load(object sender, EventArgs e)
        {
    
        }
        
        private void FindContactEmailByName() {
    
            //firstName = args1;
            //lastName = args2;
            Outlook.NameSpace outlookNameSpace = oApp.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;
            }
            /\*\*/
        }
        private void button1\_Click(object sender, EventArgs e)
        {
            firstName = "Tom";
            lastName = "Lee";
            popup();
        }
    
        private void button2\_Click(object sender, EventArgs e)
        {
            firstName = "Peter";
            lastName = "Green";
            popup();
        }
        void popup() {
            Thread th = new Thread(FindContac
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups