1
I am reading an excel file (xls, xlsx, csv) and displaying its contents on a new page using Dataset. I can do 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 pretty close to what I wanted using byte[]
, but I can’t figure out what I need to do to turn these byte[]
in DataSet
.
Any idea?
PS: I know I might be doing wrong, so I’m open to displaying this file . csv in any other way.
Thanks! I made some modifications to my code and managed to adapt :)
– Csorgo