Hi.
I have am using c# and the outlook object model to access the outlook
address book, but once you have more than a 100 or so contacts in the
folder it takes far too long to iterate through them. When theres 3000
contacts in there it takes a whole minute to iterate through them. My
Code is at the end of the post. You can see I have commented out the
dialog box filling section, to see that thats not causing the slowdown,
its the contact = (Outlook.ContactItem) contactItems.Item (counter);
that seems to be slowing things down.
I know it can be done faster because Outlook itself gets all contacts in
its window instantly, and if one uses the mapi32.dll from c++ for
example with MAPILogonEx , OpenAddressBook, and IAddrBook::Address the
contacts appear instantly too. (I cant do this however as I dont want
the default outlook supplied UI)
Any suggestions as to a quicker way to get the contacts in?
Heres my code, its pretty standard copied out of the newsgroups stuff:
private void
GetInfo ()
{
string contactFolderName;
string entryIdFolder;
string entryIdStore;
Outlook.MAPIFolder contactsFolder;
Outlook.Items contactItems;
Outlook.ContactItem contact;
Outlook.NameSpaceClass nameSpace =
(Outlook.NameSpaceClass) oa.GetNamespace ("mapi");
nameSpace.Logon (Environment.UserName, "", true, true);
// Here we need to let the user choose a folder.
//contactsFolder = nameSpace.PickFolder();
try
{
if (Application.UserAppDataRegistry.GetValue ("ContactsFolder") !=
null)
{
// Bits related to registry reading snipped
contactsFolder =
nameSpace.GetFolderFromID (entryIdFolder, entryIdStore);
}
else
{
contactsFolder =
nameSpace.GetDefaultFolder (Outlook.OlDefaultFolders.
olFolderContacts);
}
}
// Catch snipped
contactItems = contactsFolder.Items;
int counter = 0;
ContactPicker cp = new ContactPicker ();
for (counter = 1; counter <= contactItems.Count; counter++)
{
contact = (Outlook.ContactItem) contactItems.Item (counter);
//message = contact.FullName;
//System.Windows.Forms.MessageBox.Show(message);
//contact.Display(true);
/*
ListViewItem newItem = new ListViewItem(contact.FullName,
counter-1);
newItem.SubItems.Add(contact.MailingAddressPostalC ode);
newItem.SubItems.Add(contact.MailingAddressCity);
newItem.SubItems.Add(contact.MailingAddressStreet) ;
newItem.SubItems.Add(contact.BusinessTelephoneNumb er);
newItem.SubItems.Add(contact.HomeTelephoneNumber);
newItem.SubItems.Add(contact.MobileTelephoneNumber );
newItem.SubItems.Add(contact.BusinessFaxNumber);
cp.lstContacts.Items.Add(newItem);
//Console.WriteLine(contact.FullName);
*/
}
cp.lstContacts.Sorting = System.Windows.Forms.SortOrder.Ascending;
cp.lstContacts.Sort ();
cp.Show ();
nameSpace.Logoff ();
contactItems = null;
contactsFolder = null;
nameSpace = null;
oa = null;
//return null;
}