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' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -