Multiple file selection into list window

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erwabo
    New Member
    • Jun 2012
    • 1

    Multiple file selection into list window

    I am VERY new to Scripting. All I am trying to do is have a button that lets me select a multiple files and then list them in a window below the button (for selection later). I have figured out how to at least OPEN the windows but when I select multiple files I get an error "NullRefere nce Exception was unhandled"

    Anyhow my starting code is below. Any assistance would be great. Thanks

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim openFileDialog1 As New OpenFileDialog
            Dim fName As String
    
            openFileDialog1.InitialDirectory = "c:\"
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            openFileDialog1.FilterIndex = 2
            openFileDialog1.RestoreDirectory = True
            openFileDialog1.Multiselect = True
    
            If openFileDialog1.ShowDialog() = DialogResult.OK Then
    
                For Each fName In openFileDialog1.FileNames
                    lstWrkFiles.Items.Add(fName)
                Next
            End If
    Last edited by PsychoCoder; Jun 27 '12, 07:40 PM. Reason: Added code tags
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    debug it to check in what line you're getting the error.

    I'll assume it's in the FOR, since the 'correct' syntax would be something like

    For Each fName as [dunno this object] in openfiledialog1 .Filenames

    HTH

    Comment

    Working...