0

I'm trying to read an excel file from the input Stream.

I want to read line by line and save the column information from Excel to Database.

I'm unable to read the file, Can any one help me to figure out what Im missing.

Here is the code below.

 using (System.IO.BinaryReader sr = new System.IO.BinaryReader(fileToUpload.PostedFile.InputStream))
                            {

                                do
                                {
                                    tester.Text = tester.Text + sr.ReadString() + "</br>";

                                } while (sr.PeekChar() > 0);
                            }

Thanks karthik

KNC
  • 94
  • 5
  • Do a search for how to read an excel file with C#. http://stackoverflow.com/search?q=Read+excel+file+c%23 – Seth Flowers Apr 10 '17 at 18:29
  • Possible duplicate of [Read excel file from a stream](http://stackoverflow.com/questions/560435/read-excel-file-from-a-stream) – Sorceri Apr 10 '17 at 18:30
  • Our server does not have microsoft office DLL and does not allow third party libraries to get installed. So Im trying to achieve using Binarystream. Please do let me know if any other ways to try – KNC Apr 10 '17 at 18:37

1 Answers1

-1

Normally, in text file, we read line-by-line. I doubt whether Excel also brings data line-by-line (or) you will be able to recognize End-of-line character. If you correlate Excel's row as line, that could be wrong. May be you can try with CSV file, which can be read line-by-line and can be processed as individual lines.

Barani
  • 48
  • 4
  • But I'm getting the input stream which has data that needs to be saved in database – KNC Apr 10 '17 at 18:32
  • Are you able to recognize end-of-line character from your binary stream? when you get Excel data, as everything is 1 & 0, you will be able to read them as binary stream. But, the need is to process them as textual data when you have binary data on hand. – Barani Apr 10 '17 at 18:36
  • Im able to detect the end of stream using the condition in while statement. The Real problem is reading the textual data from the stream – KNC Apr 10 '17 at 18:42