public ActionResult UploadFile() { return View(); } [HttpPost] public ActionResult UploadFile(HttpPostedFileBase file) { if (file.ContentLength > 0) { try { var filename = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("../images/"), filename); file.SaveAs(path); } catch (Exception ex) { throw ex; } } return RedirectToAction("Login"); }
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>UploadFile</title> </head> <body> <div> <% using (Html.BeginForm("UploadFile", "Account", FormMethod.Post, new {enctype = "multipart/form-data" })) {%> <div><input type="file" id="file" name="file" /></div> <div> <input type="submit" value="Upload" /></div> <%} %> </div> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)