c# - File upload control in asp.net mvc -
i have written fileupload control in asp.net mvc.but of logic doing is, downloading excel file in server locally , processing data , pushing in oracle database.but servers due permission issues , not able retrieve data downloaded server or download in server in either way. have logic convert uploading files in stream or ever rather downloading in server locally .i dont know whether can implement httppostedfilebase.inputstream
if how can implement here?
view
@using (html.beginform("upload", "mnis", formmethod.post, new { enctype = "multipart/form-data" })) { @*<div> <label for="file">filename:</label></div> <div class="uploadfirst"> <input type="file" name="file" id="file" /></div> @html.label("lbl", "psite_slno"); <input id="text1" name="txtsln" type="text" /> <div class="upload"> <input value="submit" type="submit" /></div>*@ <table> <tr><td><label for="file">filename:</label></td><td><input type="file" name="file" id="file" /></td></tr> <tr><td></td><td class="positions"><input value="submit" type="submit" /></td></tr> </table> } controller [httppost] public actionresult upload(httppostedfilebase file) { try { if (file.contentlength > 0) { int slno = (int)(session["slnum"]); string st = file.filename.tostring(); //st = server.mappath("~/")+st; st = path.combine(server.mappath("~/"), st); file.saveas(st); //start(st, slno); task.factory.startnew(() => { thread.currentthread.name = "maximo thread"; start(st, slno); }); var filename = path.getfilename(file.filename); var path = path.combine(server.mappath("~/app_data/uploads"), filename); redirecttoaction("index"); // file.saveas(path); } }
try this:
you can stream inputstream
of fileuplpad control can convert stream byte array saving database
stream stream = file.postedfile.inputstream; byte[] bytearray = readfully(stream); public static byte[] readfully(stream input) { byte[] buffer = new byte[input.length]; using (memorystream ms = new memorystream()) { int read; while ((read = input.read(buffer, 0, buffer.length)) > 0) { ms.write(buffer, 0, read); } return ms.toarray(); } }
Comments
Post a Comment