Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i am trying to update the file path, it will stored in database like
System.Web.HttpPostedFileWrapper
. Anyone please give a solution for this in ASP.NET MVC

What I have tried:

Conttroller :
[HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult EditCandidate(Candidate _candidate, HttpPostedFileBase _resume)
        {
           if (ModelState.IsValid)
            {
                var model = _db.Candidates.Find(_candidate.CandidateId);
                string oldResumePath = model.ResumePath;
                if(_resume != null && _resume.ContentLength > 0)
                {
                    var ResumeName = Path.GetFileName(_resume.FileName);
                    string path = System.IO.Path.Combine(Server.MapPath("~/Resume/"), ResumeName);
                    _resume.SaveAs(path);
                    model.ResumePath = "/Resume/" + _resume.FileName;
                    string fullPath = Request.MapPath("~" + oldResumePath);
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }
                }
                model.FirstName = _candidate.FirstName;
                model.LastName = _candidate.LastName;
                model.Email = _candidate.Email;
                model.ContactNo = _candidate.ContactNo;
                model.SkypeId = _candidate.SkypeId;
                model.CategoryId = _candidate.CategoryId;
                model.YearId = _candidate.YearId;
                model.DegreeId = _candidate.DegreeId;
                model.CourseId = _candidate.CourseId;
                model.StatusId = _candidate.StatusId;
                model.SkillId = string.Join(",", _candidate.SkillIdArray);
                model.ResumePath = _candidate.ResumePath;

                _db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
                return RedirectToAction("ListCandidate");
            }
return View(_candidate);
}



View
@Html.LabelFor(model => model.ResumePath, "Resume :", new { @class = "control-label" })
                           <div>
                               @Html.TextBoxFor(model => model.ResumePath, new { @class = "form-control", type = "file", name = "_resume", tabindex = 12 })
                           </div>
                           <span>@Html.DisplayFor(model => model.ResumePath)</span>
                           @Html.ValidationMessageFor(model => model.ResumePath, "", new { @class = "text-danger" })
Posted
Comments
j snooze 13-Mar-18 17:11pm    
What is the problem or error you are experiencing?
kmuthu1212 14-Mar-18 1:18am    
The filepath is update like System.Web.HttpPostedFileWrapper, why the file path is not saving in the database
Laxmidhar tatwa technologies 14-Mar-18 7:24am    
Do not use textboxfor
Use like


Again the view code

@using(HTML.begin form("action name","controler",form method.post,
new { enctype="multiparty/form-data"}))
Laxmidhar tatwa technologies 14-Mar-18 7:25am    
Use tag input type="file" name="file"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900