<form action="" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <input type="submit" /> </form>
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; namespace GMS1.Controllers { public class FileUploadController : Controller { // // GET: /FileUpload/ public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(HttpPostedFileBase file) { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/UserImages/"), fileName); file.SaveAs(path); } return RedirectToAction("Index"); } } }
@using (Html.BeginForm("Index", "FileUploader", FormMethod.Post, new { enctype = "multipart/form-data" })) { <label for="file">Filename:</label> <input type="file" name ="file" id="file" /> <input type="submit" /> }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)