asp.net mvc - Upload File in MVC and create a link to Download the the file -
i have created code upload file. not upload file in app_data/uploads folder have created. here code>>
in view>> <form action="~/views/home/_saveupdate" method="post" enctype="multipart/form-data"> <label for="file1">filename:</label> <input type="file" name="files" id="file1" /> <label for="file2">filename:</label> <input type="file" name="files" id="file2" /> <input type="submit" /> </form> , handler>> [httppost] public actionresult index(ienumerable<httppostedfilebase> files) { foreach (var file in files) { if (file.contentlength > 0) { var filename = path.getfilename(file.filename); var path = path.combine(httpcontext.server.mappath("~/app_data/uploads"), filename); file.saveas(path); } } return redirecttoaction("index"); }
please tell me more needs done. also, how generate link download file.
first, action of form points ~/views/home/_saveupdate
while should /home/index
based on post-action. second, make sure have created upload folder inside app_data folder. should take care of upload problem.
view:
<form action="/home/index" method="post" enctype="multipart/form-data"> <label for="file1">filename:</label> <input type="file" name="files" id="file1" /> <label for="file2">filename:</label> <input type="file" name="files" id="file2" /> <input type="submit" /> </form>
if want display download links uploaded files, should store images in different folder app_data. app_data folder not directly accessible due security reasons.
a example show files in directory can found here
Comments
Post a Comment