c# - How to write .csv from request stream -
i trying upload .csv files website server .
the files copied server fine , same size uploaded .csv files.
the problem when open .csv files on server content of file empty.
here uploader method:
public bool uploadcsvfile(stream uploadfilestream, string fileextension) { byte[] filedata = new byte[(int)uploadfilestream.length]; string hashname = bitconverter.tostring(md5cryptoserviceprovider.create().computehash(filedata)).replace("-", string.empty); datetime = datetime.now; string originalimagename = hashname + now.year + now.day + now.month + now.hour + now.minute + now.second + now.millisecond + fileextension; var dropfolder = configurationmanager.appsettings["mydrop"]; var filenamepath = path.combine(dropfolder, originalimagename); try { try { var filestream = file.create(filenamepath); filestream.write(filedata, 0, filedata.length); filestream.close(); //i tried this: //var filestream = file.create(filenamepath, (int)uploadfilestream.length); // filestream.read(filedata, 0, filedata.length); //filestream.write(filedata, 0, filedata.length); // filestream.close(); } catch (exception exc) { throw exc; } } catch (exception ex) { throw ex; } return true; }
you should able done as:
var filestream = file.create(filenamepath); uploadfilestream.copyto(filestream);
Comments
Post a Comment