I have a text file that has data line by line. I am trying to put the lines of data into an array or list.
Dim req As WebRequest = WebRequest.Create("http://www.blahblah.com/data/ListFull.csv")
Dim res As WebResponse = req.GetResponse()
Dim stream As Stream = res.GetResponseStream()
Dim sr As StreamReader = New StreamReader(stream, Encoding.ASCII)
Dim streamString As String = sr.ReadToEnd
'#1
Dim lines1 As String()
If streamString.Length > 0 Then
lines1 = streamString.Split(vbLf)
End If
'#2
Dim lines2 As New List(Of String)
Using r As StreamReader = New StreamReader(stream, Encoding.ASCII)
Dim line As String
line = r.ReadLine
Do Until String.IsNullOrEmpty(line)
lines2.Add(line)
'counter += 1
'line = r.ReadLine
Loop
End Using
I have option one working fine, and all of the file data is going into my lines1 array.
Option 2 however is not working. When I step through the code: line = r.ReadLine is null/nothing. Why isnt the stream being read in and what am I doing wrong?
'line = r.ReadLine: it works fine for me. The linesr.ReadToEndwould be used for the first thing only, since for the second since you want to read line by line.