Toqeer Yousaf
Toqeer Yousaf

Reputation: 414

Could not find a part of the path 'c:\users\dell\documents\visual studio 2015\Projects\CreateCon\CreateCon\Content\Images\1.png'

[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

Answers (1)

Razmik Ghookas
Razmik Ghookas

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

Related Questions