Jump to content


Photo

Cannot open 2 or more outlook contact detail


  • Please log in to reply
No replies to this topic

#1 manfree

manfree

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 07 April 2009 - 05:39 AM

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(FindContactEmailByName);
			th.Start();
		}
	}
}

Attached Files


Edited by manfree, 07 April 2009 - 09:08 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users