By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Multiple file selection into list window

P: 1
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 "NullReference Exception was unhandled"

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         Dim openFileDialog1 As New OpenFileDialog
  4.         Dim fName As String
  6.         openFileDialog1.InitialDirectory = "c:\"
  7.         openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
  8.         openFileDialog1.FilterIndex = 2
  9.         openFileDialog1.RestoreDirectory = True
  10.         openFileDialog1.Multiselect = True
  12.         If openFileDialog1.ShowDialog() = DialogResult.OK Then
  14.             For Each fName In openFileDialog1.FileNames
  15.                 lstWrkFiles.Items.Add(fName)
  16.             Next
  17.         End If
Jun 27 '12 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,295
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

Jul 3 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.