I'm reading an excel file (xls, xlsx, csv) and displaying its contents on a new page using DataSet. I can do it for xls and xlsx, but for csv it's not rolling.
public static DataSet result;
public static void prepareFile(HttpPostedFileBase file) {
Stream stream = file.InputStream;
IExcelDataReader reader = null;
byte[] fileDataCsv;
if (file.FileName.EndsWith(".csv")) {
BinaryReader binaryReader = new BinaryReader(file.InputStream, Encoding.UTF8);
fileDataCsv = binaryReader.ReadBytes(file.ContentLength);
showCsv(fileDataCsv);
} else if (file.FileName.EndsWith(".xls")) {
reader = ExcelReaderFactory.CreateBinaryReader(stream);
showXls(reader);
} else if (file.FileName.EndsWith(".xlsx")) {
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
showXls(reader);
} else {
//TODO: Message error
return;
}
}
I saw in some forums some people getting close to what I wanted using byte[]
, but I can not figure out what I need to do to turn those byte[]
into DataSet
.
Any ideas?
PS: I know I might be doing wrong, so I'm open to displaying this .csv file in any other way.