473,761 Members | 10,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Contac tItem) contactItems.It em (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::Addr ess 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 contactFolderNa me;
string entryIdFolder;
string entryIdStore;
Outlook.MAPIFol der contactsFolder;
Outlook.Items contactItems;
Outlook.Contact Item contact;

Outlook.NameSpa ceClass nameSpace =
(Outlook.NameSp aceClass) oa.GetNamespace ("mapi");
nameSpace.Logon (Environment.Us erName, "", true, true);

// Here we need to let the user choose a folder.

//contactsFolder = nameSpace.PickF older();
try
{
if (Application.Us erAppDataRegist ry.GetValue ("ContactsFolde r") !=
null)
{
// Bits related to registry reading snipped
contactsFolder =
nameSpace.GetFo lderFromID (entryIdFolder, entryIdStore);
}
else
{
contactsFolder =
nameSpace.GetDe faultFolder (Outlook.OlDefa ultFolders.
olFolderContact s);
}
}
// Catch snipped
contactItems = contactsFolder. Items;

int counter = 0;

ContactPicker cp = new ContactPicker ();

for (counter = 1; counter <= contactItems.Co unt; counter++)
{
contact = (Outlook.Contac tItem) contactItems.It em (counter);
//message = contact.FullNam e;
//System.Windows. Forms.MessageBo x.Show(message) ;
//contact.Display (true);
/*
ListViewItem newItem = new ListViewItem(co ntact.FullName,
counter-1);

newItem.SubItem s.Add(contact.M ailingAddressPo stalCode);
newItem.SubItem s.Add(contact.M ailingAddressCi ty);
newItem.SubItem s.Add(contact.M ailingAddressSt reet);
newItem.SubItem s.Add(contact.B usinessTelephon eNumber);
newItem.SubItem s.Add(contact.H omeTelephoneNum ber);
newItem.SubItem s.Add(contact.M obileTelephoneN umber);
newItem.SubItem s.Add(contact.B usinessFaxNumbe r);

cp.lstContacts. Items.Add(newIt em);
//Console.WriteLi ne(contact.Full Name);
*/

}
cp.lstContacts. Sorting = System.Windows. Forms.SortOrder .Ascending;
cp.lstContacts. Sort ();

cp.Show ();

nameSpace.Logof f ();

contactItems = null;
contactsFolder = null;
nameSpace = null;
oa = null;
//return null;
}
Jul 21 '05 #1
2 3313
cribe
2 New Member
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 New Member
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("Out look.Applicatio n");
objOutlook.Crea teInstance(__uu idof(Applicatio n));
objOutlook->GetNamespace(C ComBSTR("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
19346
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 or my conversion skills are weak. And if I have to use tlbimp.exe what is the right file to use. Thanks for the help. -- Fritz
0
1558
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 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...
1
2657
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 folder: Dim objFolder As Outlook.MAPIFolder Dim objItem As Object Dim colItems As Items Dim objItem2 As ContactItem
3
6048
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 the error on the indicated line. Any help would be appreciated. Thanks Regards
7
3628
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 get to item 250 i get a "system.invalid cast exception" and "specified cast is not valid". Once i get this error and try to go to the next record.. every record after gets the same error... It's like the com connection to outlook has been lost....
1
4346
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 contacts info in them. When I export contacts from access to outlook, it takes a long time because there are so many contacts in the Outlook address book, and it is checking all of these against the contacts coming in, so as to avoid duplicates....
1
4867
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 2002(10.2627.2625) I can create a contact in Outlook and I can use it to send an email. It's just the getting the contacts list that doesn't work. The thing is it also works on my dev machine but not on the users machine. The code I'm using: SecurityManager =...
1
4589
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 contact folder called "Yacht Club" How do I change the "active folder" from Contacts to "Yacht Club" Existing code here:
0
1116
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 of the contacts in the folder. Can someone see what I'm doing incorrectly?
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.