Hi,
I am trying to open a remote file to read the header row to establish which columns the file has. The code below works but takes ages with a large file. I have a feeling the whole files contents is being read into memory?
Is it possible to read a header row of a remote file without reading the whole file into memory? the files I want to peek at will have 500K + rows so I need a quick and efficient solution.
any help would be much appreicated.
Thanks
David
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
Dim theStream As Stream = File1.PostedFile.InputStream
Dim tmpArray() As String
Using sr As New StreamReader(theStream)
Dim line As String = sr.ReadLine()
For x As Integer = 0 To 0
tmpArray = line.Split(Convert.ToChar(ddlDelimiter.SelectedValue))
line = sr.ReadLine() ' CRITICAL line else you will go in an endless loop
Next x
End Using
'ListBox1.Focus()
'ListBox1.DataSource = tmpArray
For y As Integer = 0 To tmpArray.Length - 1
lblColumnHeaders.Text += tmpArray & vbCrLf
Next
End Sub
I am trying to open a remote file to read the header row to establish which columns the file has. The code below works but takes ages with a large file. I have a feeling the whole files contents is being read into memory?
Is it possible to read a header row of a remote file without reading the whole file into memory? the files I want to peek at will have 500K + rows so I need a quick and efficient solution.
any help would be much appreicated.
Thanks
David
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
Dim theStream As Stream = File1.PostedFile.InputStream
Dim tmpArray() As String
Using sr As New StreamReader(theStream)
Dim line As String = sr.ReadLine()
For x As Integer = 0 To 0
tmpArray = line.Split(Convert.ToChar(ddlDelimiter.SelectedValue))
line = sr.ReadLine() ' CRITICAL line else you will go in an endless loop
Next x
End Using
'ListBox1.Focus()
'ListBox1.DataSource = tmpArray
For y As Integer = 0 To tmpArray.Length - 1
lblColumnHeaders.Text += tmpArray & vbCrLf
Next
End Sub