CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    4

    Resolved [RESOLVED] Unable to open 2 or more outlook contact detail

    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


    Code:
    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(FindContactEmailByName);
                th.Start();
            }
        }
    }
    Attached Files Attached Files
    Last edited by manfree; April 13th, 2009 at 10:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured