0

I want to select a text file using a FileUpload control and read it into a string array.

I would like to understand if instead of using StreamReader.ReadLine I can use File.ReadLines.

I searched for some examples online but always find FileUpload control associated with StreamReader. I am missing the knowledge to understand why.

To complete the question: I am working on a web application. I am using StreamReader and it works fine but if I try to use File.ReadLines(path) where path is FileUpload1.FileName I cannot get the fullpath.

Endovelicvs
  • 109
  • 1
  • 11

1 Answers1

0

Have you checked the difference between these two?

If not, please try to google and check. then you will find what you are looking for.

For you reference i am posting some links that will help you to understand it:

Is StreamReader.Readline() really the fastest method to count lines in a file?

The difference between StreamReader.ReadLine and File.ReadLines?

File.ReadAllLines or Stream Reader

Community
  • 1
  • 1
Ram Singh
  • 6,664
  • 35
  • 100
  • 166
  • My question probably is less smarter than that. To use `File.ReadLines(fullpath)` I need the path of the file. How am I able to retrieve it using a FileUpload control? – Endovelicvs Feb 10 '16 at 10:01
  • @Endovelicvs: FileUpload must expose a property with the path of the selected file for upload. That is the path you can use for File.ReadLines – Veverke Feb 10 '16 at 10:03
  • Path.GetFullPath((new Uri(absolute_path)).LocalPath); – Ram Feb 10 '16 at 10:23