c# - Take contents of an excel file (.xls or .xlsx) in to Dataset -


i have excel file named test.xls , want contents in excel sheet dataset.is possible tried code throws exception,here code

 string filepath = server.mappath("portals\\_default") + "\\" + upprice.filename;  upprice.postedfile.saveas(filepath);  filestream stream = file.open(filepath, filemode.open,    fileaccess.read);  if (upprice.filename.contains(".xlsx"))  {   iexceldatareader excelreader = excelreaderfactory.createbinaryreader(stream);    dataset result = excelreader.asdataset();  } 

i'm going assume you're using http://exceldatareader.codeplex.com/

from code:

if (upprice.filename.contains(".xlsx"))  {   iexceldatareader excelreader = excelreaderfactory.createbinaryreader(stream);    dataset result = excelreader.asdataset();  }  else if (upprice.filename.contains(".xls"))  {   iexceldatareader excelreader = excelreaderfactory.createopenxmlreader(stream);   dataset result = excelreader.asdataset();  }  

these tests backwards. ".xlsx" files zipped xml documents. "xls" older binary files. consider using system.io.path.getextension() file extension since you'll notice contains(".xls") true both file types.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -