Reputation: 414
[HttpPost] public ActionResult Index1(HttpPostedFileBase doc) { var path = ""; if(doc != null) { if(doc.ContentLength>0) { //check image type or not if (Path.GetExtension(doc.FileName).ToLower() ==".jpg" || Path.GetExtension(doc.FileName).ToLower() == ".png" ||Path.GetExtension(doc.FileName).ToLower() == ".jpeg") { path = Path.Combine(Server.MapPath("/Content/Images"), doc.FileName); doc.SaveAs(path); ViewBag.UploadSeccess = true; } } } return View(); }
Upvotes: 0
Views: 529
Reputation: 118
change this part of code
path = Path.Combine(Server.MapPath("/Content/Images"), doc.FileName);
to:
path = Path.Combine(Server.MapPath("~/Content/Images"), doc.FileName);
Upvotes: 1