473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

accessing contacts in mapifolder way too slow

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;
}
Jul 21 '05 #1
2 3272
cribe
2
Hi,

I too have noticed that getting contact data is slow. But have you noticed that setting it is extremely slow for phone numbers! I am testing a C++ Com Add-in and am synchronizing contacts from a server to Outlook. My bottleneck is the darn contact phone number entries it takes 1 to 2 seconds per entry! :mad:

Have you seen this problem before? Do you have any suggestions?
(Under outlook 2003 the problem is more apparent!)
Thanks in advance!
Chris
Mar 9 '06 #2
cribe
2
Hi again,

I found the solution/workaround to my problem(s): Performance and the deleted items not showing the correct parent. Well in C++ anyway.

What I did was create a new instance of Outlook withing the plugin and get the MAPI namespace from there. That solves the deleted items not deleting and is a heck of a lot quicker since it does not seem to trigger the Tapi32.dll and Rtutils.dll (Telephony stuff).

//-------------------------------------------------------------------------
// This is the correct method of connecting to the outlook model
// (MAPI + new Outlook instance) this method is faster than using the
// application reference passed to the plugin. This seems to be because
// no default outlook automation occurs in this state.
//-------------------------------------------------------------------------
_ApplicationPtr objOutlook("Outlook.Application");
objOutlook.CreateInstance(__uuidof(Application));
objOutlook->GetNamespace(CComBSTR("MAPI"),&olNs);


Hope that solves your problem too.
Chris
Mar 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fritz Switzer | last post by:
Can anyone provide a small snippet in C# that pulls out the Contacts in Outlook XP. I've seen a couple of examples in C++ and VB in previous newsgroup posts, but either the originals didn't work...
0
by: Kurt Häusler | last post by:
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...
1
by: Chris Thunell | last post by:
I need to loop through a public folder on our exchange server and get some information out of each record... I have the following code, but I can't seem to figure out how to reference the public...
3
by: John | last post by:
Hi I am trying to access outlook contacts folders and delete the contacts that do not contain a certain category value in the categories field. I have written the below code but am stuck with...
7
by: Chris Thunell | last post by:
I'm trying to loop through an exchange public folder contact list, get some information out of each item, and then put it into a vb.net datatable. I run though the code and all works fine until i...
1
by: charliej2001 | last post by:
Hi all My access database has import/export capabiltiy of contact details between outlook. The database is getting big now (1000+ contacts) and so are the outlook address books that have the...
1
by: dcd | last post by:
Hi all I'm using trying to get my app to read in all contacts in the contact folder of Outlook. I'm using the Outlook Security manager to stop the pop up warnings. Outlook version is...
1
by: Phil Stanton | last post by:
I have a Yacht Club Db with names addresse phone nos, emails etc. I want to export them to Outlook. No problem in getting them into the contact folder. My problem is I have a folder within the...
0
by: Bob | last post by:
Hi All, Please let me know the correct group if this is in the wrong place. I am trying to delete all Outlook contacts in a folder. For some reason, the following code deletes exactly half...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.