Last post May 05, 2009 06:15 AM by davida37
May 02, 2009 08:22 AM|davida37|LINK
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
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
'ListBox1.DataSource = tmpArray
For y As Integer = 0 To tmpArray.Length - 1
lblColumnHeaders.Text += tmpArray(y) & vbCrLf
May 05, 2009 06:04 AM|BlueJam|LINK
That code looks ok, I suspect the thing that is taking a long time is the actual HTTP Upload itself.
May 05, 2009 06:15 AM|davida37|LINK
right - thats the problem. The time is takes to do the HTTP upload. Any other possible solutions?
Please correct me if I am wrong - but the only options I see which seem to be available are:
1) Upload the file (using a fileUpload control) to get the file locally on the processing
web server, then examine the file locally on the server. As I will need to upload the file eventually anyway.
Ideally, I would still like to examine the header row of a file on a users/client machine to examine the header row before uploading the file.