I am trying to open a file and read it into a list box, using the open dialog box. I get as far as selecting a file but then nothing happens. Can anyone show me my error(s)?
Attached is the sample file that I would like to read in. It is just a test file. Thanks.
CODE
Private Sub EmpFile_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles EmpFile.FileOk
Dim inputFile As System.IO.StreamReader
If EmpFile.ShowDialog() = Windows.Forms.DialogResult.OK Then
MessageBox.Show(EmpFile.FileName)
With EmpFile
.Filter = "Text files (*.txt)|*.txt|All Files(*.*)|*.*"
.InitialDirectory = "C:\Documents and Settings\Me\Desktop\WITCC\3rd Quarter Classes\VB\EmployeeData Part 3\EmployeeData Part 3\bin\Debug\Employee_Data2.txt"
.Title = "Select file to open"
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
inputFile = File.OpenText(.FileName)
ListBox1.Items.Add(inputFile.ReadLine())
inputFile.Close()
End If
End With
Else
MessageBox.Show("You Selected No File", "File Selection")
End If