title: Read multiple text files in a folder
body: <p>I have many text files in a folder. What I can do now is to read through one text at a time and insert it into the database. My little app reads a text file when I debug it. So, I need to run it several times to read all those text files and import them into the database.</p>
  
  <p>My question is how to read multiple text files inside a folder at a time. Here's my code which works fine but it reads only one text files at a time.</p>
  
  <pre><code>Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
  
          Dim filelocation As String
          filelocation = "F:\txtfiles\ch25.txt"
          Dim chid As Integer
          chid = 25
  
  
  
          'read from file'
          Dim MyStream As New StreamReader(Path.Combine(Application.StartupPath, filelocation))
          Dim vArray() As String = MyStream.ReadToEnd.Split(CChar("$"))
          MyStream.Close()
  
  
  
          Dim count As Integer
  
          'insert text to table'
          For d As Integer = 0 To vArray.Length - 1 Step 1
  
              If d = vArray.Length - 1 Then
                  Exit For
              End If
  
              InsertKh(chid, d + 1, vArray(d))
              count = d + 1
          Next
  
  
         MsgBox ("Done Inserting")
  
  End Sub
  </code></pre>
  
  <p>Obviously, I need a way to loop through a folder and check if there's text file. But I cant get it right. Can anyone show me some code or links ? I'm using VB.NET, .NET 3.5</p>
  
  <p>Thanks so much.</p>