Solved

Outlook contacts to ListView- code is slow!

Posted on 2012-04-09
7
241 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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