Upload file and read contents from the stream?

  • Thread starter Thread starter Chris Holliday
  • Start date Start date
C

Chris Holliday

I would like to provide an interface for users to upload a csv (or other
text file). I would like to read the contents of the CSV while it is
uploading (from the stream). Is this possible? It is no trouble to read it
once it is saved, but I was thinking I could possibly save a step.

Thanks,

Chris
 
Chris Holliday said:
I would like to provide an interface for users to upload a csv (or other
text file). I would like to read the contents of the CSV while it is
uploading (from the stream). Is this possible? It is no trouble to read it
once it is saved, but I was thinking I could possibly save a step.
For the archives:

This is easily handled by doing something like the following:

Dim str As Stream

str = MyFile.PostedFile.InputStream()

Dim myText As String

Dim sb As New System.Text.StringBuilder()

Dim sr As StreamReader = New StreamReader(str)

myText = sr.ReadLine()



In the above, MyFile is the file input from the webform.



Thanks,



C.
 
HttpPostedFile.InputStream

Gets a Stream object which points to an uploaded file to prepare for reading
the contents of the file.

Read directly from this, and you never have to call the SaveAs method first.


I was minding my own business when Chris Holliday blurted out:
 
Back
Top