Wednesday, December 30, 2015

How to upload a file in an ASP.Net MVC






step_1
file id uploadFile



on ProfilePicture.cshtml



step_2 [HttpPost]
public ActionResult ProfilePicture()
{
HttpPostedFileBase photo = Request.Files["uploadFile"];
string uploadedPath = "Content\\images\\profileimages\\";
string sFileDir = System.Web.HttpContext.Current.Server.MapPath("~") + uploadedPath;
if (photo.ContentLength > 0)
{
string sFileName = System.IO.Path.GetFileName(photo.FileName);
photo.SaveAs(sFileDir + sFileName);
}
}




step_3 in Request.Files["uploadFile"];



and enjoy

No comments:

Post a Comment