Solved

Outlook contacts to ListView- code is slow!

Posted on 2012-04-09
7
242 Views
Last Modified: 2012-05-14
i am trying to get my Outlook contacts to display in a listview.

Using the code below, it takes some time to get just 150 contacts (where I am testing the app).

Any suggestions for making this go faster?

Code:

             Dim TempStr() As String
            Dim TempNode As ListViewItem
            Dim TempArr() As ListViewItem
            Dim i As Integer

 

            ReDim TempStr(6)
 
            objAddressList = _
                   objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)

            'Get all the contacts

            Dim itm As New ListViewItem
            Dim strOutlookInfo(10) As String

            objItems = objAddressList.Items

            For j = 1 To objItems.Count

                If objItems(j).class = 40 Then
                     TempStr(0) = objItems(j).entryid
                    TempStr(1) = objItems(j).title
                    TempStr(2) = objItems(j).firstname
                    TempStr(3) = objItems(j).middlename
                    TempStr(4) = objItems(j).lastname
                    TempStr(5) = objItems(j).suffix
                    TempStr(6) = objItems(j).email1address

                    TempNode = New ListViewItem(TempStr)
                    TempNode.Tag = objItems(j).entryid

                    ReDim Preserve TempArr(i)
                    TempArr(i) = TempNode
 
                    i += 1

                End If
             Next

             lvwOutlook.Items.AddRange(TempArr)
0
Comment
Question by:scbdpm
  • 3
  • 2
  • 2
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37827596
If this is a Windows Forms ListView, the first thing to try is to use ListView.BeginUpdate before loading, and ListView.EndUpdate after.  This prevents the control from drawing, while items are loaded.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37832919
I bet the slowness is in communication between your app and Outlook and there is nothing you can do about that. You may want to try something else like CDO to interact with Outlook instead of managed API but I am not sure how much difference it would make performancewise.
0
 

Author Comment

by:scbdpm
ID: 37833441
CodeCruise,
I think you are correct as I did some experimenting with timing and it was more on the 'grab from Outlook' side than  the actually load ListView.

Not familiar with CDO. can you direct me to some info?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 37833850
How much time does it take to get 150 contacts?
0
 

Author Comment

by:scbdpm
ID: 37833857
about 4-5 seconds.... but that is my home outlook and I'd like to use for my work outlook of 350+...
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37834352
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 37834554
I wonder if Redemption suffers from the same problem.  That is what I use, and there is an interface to get IRDOContactItem information.

Redemption is a free download for developers, which a fee for deployment licenses.

Download Redemption
http://www.dimastr.com/redemption/download.htm

C# example as a proof-of-concept:

            RDOFolder contactsFolder = this.redemptionSession.GetDefaultFolder(rdoDefaultFolders.olFolderContacts);

            List<OutlookContact> contactList =
                contactsFolder.Items
                    .OfType<RDOContactItem>()
                    .Select(x => new OutlookContact(x))
                    .ToList();

            return contactList;

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 48
Store results in vb.net 3 24
Checking a checkbox based on SQL DataReader boolean value in ASP.NET(VB) 2 32
How to duplicate form in Visual Studio 2015 2 57
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question