473,769 Members | 2,222 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;
}
Nov 15 '05 #1
0 1558

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

Similar topics

2
19348
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
2
3315
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
2658
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
0
1170
by: TM | last post by:
I was able to find the code to list the name and email from the contacts in Outlook 2003, but the sort property is not working. Here is my sample code. For now I am just adding an item to a listbox with the fileas name so I can see what is going on. Any idea why the sort is not working to sort the contacts by FileAs name ? Dim OutlookApp As New Outlook.Application Dim OLNameSpace As Outlook.NameSpace
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
9590
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
10051
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
10000
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
9866
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...
1
7413
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.