troubleshooting Question

VB App won't populate ListBox with files found with GetFiles

Avatar of Jason Paradis
Jason ParadisFlag for United States of America asked on
Visual Basic.NET
8 Comments2 Solutions102 ViewsLast Modified:
Private Sub findPSTButton_Click(sender As Object, e As EventArgs) Handles findPSTButton.Click
        BackupperProgress.Value = 0
            For Each foundPST As String In My.Computer.FileSystem.GetFiles(
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.pst")
        Catch ex As Exception

        End Try
        BackupperProgress.Value = 99
    End Sub

According to several sources, this should do the following:

a) Start the progress bar
b) Search the current logged in User Profile folder for PST files.
c) Ignore Junction Points (i.e. My Pictures under Documents, etc) and all exceptions
d) Add all of the PST's found to the ListBox

Unfortunately, when the button is clicked nothing appears in the list box. Can anyone tell me what I've done wrong here?

EDIT: By adding a MsgBox(ex.Message) I found out that I'm still getting access denied errors. I've tried putting a Catch line after the For Each one but it blocks the foundPST variable from being used elsewhere in the code. It also says that a Next line needs to be before the Catch. But if I do that I'm back to square one.
NorieSenior Associate
Join our community to see this answer!
Unlock 2 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros