[2005] Can not read a stream line by line.
I am using the following code to read and save to file the html code of a web page and this works. When I replace
Code:
FileWriter.WriteLine(MyStream.ReadToEnd)
with
Code:
While MyStream.Peek <> -1
FileWriter.WriteLine(MyStream.ReadLine())
End While
so that I can save the stream line by line it only saves the entire html page about half of the time. The other half it saves about 50% of the html code only. Anyone know why?
Code:
Dim MyRequest As System.Net.HttpWebRequest
Dim MyResponse As System.Net.HttpWebResponse
Dim MyStream As System.IO.StreamReader
Dim FileWriter As IO.StreamWriter
MyRequest = System.Net.WebRequest.Create("http://www.domain.com")
MyResponse = MyRequest.GetResponse()
MyStream = New System.IO.StreamReader(MyResponse.GetResponseStream())
FileWriter = New IO.StreamWriter("html.txt")
FileWriter.WriteLine(MyStream.ReadToEnd)
FileWriter.Flush()
FileWriter.Close()
MyStream.Close()
MyResponse.Close()