Upload image in mvc5ASAleena Saviour9yAsked Jun 28, 2017, 2:05 AM EDT7 answersShareLinkedInXCopy linkSaveHow to upload image into server folder and save its path in database?
Upload image in mvc5ASAleena Saviour9yAsked Jun 28, 2017, 2:05 AM EDT7 answersShareLinkedInXCopy linkSaveHow to upload image into server folder and save its path in database?
Abhilash J ARank #1,243 · 1.4K reputation9y agoPosted Jun 28, 2017, 2:22 AM EDT0Hi, 1. You can use input type file html control for upload a image or multiple. 2. After upload a file, you can save this file in to the application image folder and save its name to database field as `imagename varchar(50)`. 3. You can save your image folder path inside the static class as string. 4. Then, you can retrieve the image name from db and to show Eg: <img width="135" height="135" src="../../usercontroller/[email protected]" /> Cheers!!!0
ASAleena SaviourRank #4,788 · 325 reputation9y agoPosted Jun 28, 2017, 3:17 AM EDT0Please help me with the code of first three steps?0
Abhilash J ARank #1,243 · 1.4K reputation9y agoPosted Jun 28, 2017, 3:32 AM EDT0See: https://forums.asp.net/t/1994564.aspx?How+to+pass+upload+file+to+controller+in+MVC+4+Razor+0
Rupesh KahaneRank #136 · 16.4K reputation9y agoPosted Jun 28, 2017, 4:07 AM EDT0Refere below articles 1) http://www.c-sharpcorner.com/article/uploading-files-using-strongly-typed-fileuploader-in-Asp-Net/ 2) http://www.c-sharpcorner.com/UploadFile/sourabh_mishra1/fileupload-in-Asp-Net-mvc/ 3) https://www.aurigma.com/upload-suite/developers/aspnet-mvc/how-to-upload-files-in-aspnet-mvc All the best 0
Manikandan MurugesanRank #300 · 8.4K reputation9y agoPosted Jun 28, 2017, 6:14 AM EDT0//Controller public class FileUpController : Controller { [HttpPost]3 public ActionResult Create(tbl_atmconfigform tbl_atmconfigform, HttpPostedFileBase file) { if (ModelState.IsValid) { tbl_atmconfigform.atm_filename = Path.GetFileName(file.FileName); db.tbl_atmconfigform.Add(tbl_atmconfigform); db.SaveChanges(); if (file != null && file.ContentLength > 0) try { string path = Path.Combine(Server.MapPath("~/Storage/"), Path.GetFileName(file.FileName)); if (System.IO.File.Exists(path)) { ViewBag.Message = "The File Already Exists in System"; } else { file.SaveAs(path); } } catch (Exception exception) { ViewBag.Message = "ERROR:" + exception.Message.ToString(); } else { ViewBag.Message = "Specify the file"; } return RedirectToAction("Index"); } ViewBag.c_id = new SelectList(db.tbl_client, "c_id", "c_name", tbl_atmconfigform.c_id); ViewBag.s_id = new SelectList(db.tbl_sites, "s_id", "s_name", tbl_atmconfigform.s_id); ViewBag.em_id = new SelectList(db.tbl_employee, "em_id", "em_fullname",tbl_atmconfigform.em_id); return View(tbl_atmconfigform); } public FileResult Download(int id = 0) { tbl_atmconfigform tbl_atmconfigform = db.tbl_atmconfigform.Find(id); string Filename = tbl_atmconfigform.atm_filename; return File(System.IO.Path.Combine("~/Storage/", Filename), "application/octet-stream", Filename); } //Views for Upload in create @{ ViewBag.Title = "Index"; } Basic File Upload @using (Html.BeginForm ("Index", "FileUp", FormMethod.Post, new { enctype = "multipart/form-data" })) { for="file">Upload Image: "file" name="file" id="file"/> "submit" value="Upload Image"/> @ViewBag.Message } //View for Download in Index @foreach (var item in Model) { @if(item.Filename != null) { @Html.ActionLink("Download", "Download", new { id=item.Config_ID }) } } //Make ur changes.0ASAbhishek Srivastava58 reputation9y agoPosted Jun 28, 2017, 9:26 AM EDT0https://forums.asp.net/t/1976497.aspx?ASP+Net+MVC+5+Upload+Image+Save+to+Database+Create+Thumbnail+and+Display+in+View0Vivek KumarRank #272 · 9.3K reputation9y agoPosted Jun 28, 2017, 2:30 PM EDT0Have a look into below links. https://www.aurigma.com/upload-suite/developers/aspnet-mvc/how-to-upload-files-in-aspnet-mvc https://www.mikesdotnetting.com/article/259/asp-net-mvc-5-with-ef-6-working-with-files http://highoncoding.com/Articles/689_Uploading_and_Displaying_Files_Using_ASP_NET_MVC_Framework.aspx 0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
ASAbhishek Srivastava58 reputation9y agoPosted Jun 28, 2017, 9:26 AM EDT0https://forums.asp.net/t/1976497.aspx?ASP+Net+MVC+5+Upload+Image+Save+to+Database+Create+Thumbnail+and+Display+in+View0
Vivek KumarRank #272 · 9.3K reputation9y agoPosted Jun 28, 2017, 2:30 PM EDT0Have a look into below links. https://www.aurigma.com/upload-suite/developers/aspnet-mvc/how-to-upload-files-in-aspnet-mvc https://www.mikesdotnetting.com/article/259/asp-net-mvc-5-with-ef-6-working-with-files http://highoncoding.com/Articles/689_Uploading_and_Displaying_Files_Using_ASP_NET_MVC_Framework.aspx 0
Abhilash J ARank #1,243 · 1.4K reputationPosted Jun 28, 2017, 2:22 AM EDT
Aleena SaviourRank #4,788 · 325 reputationPosted Jun 28, 2017, 3:17 AM EDT
Abhilash J ARank #1,243 · 1.4K reputationPosted Jun 28, 2017, 3:32 AM EDT
Rupesh KahaneRank #136 · 16.4K reputationPosted Jun 28, 2017, 4:07 AM EDT
Manikandan MurugesanRank #300 · 8.4K reputationPosted Jun 28, 2017, 6:14 AM EDT
Basic File Upload
Abhishek Srivastava58 reputationPosted Jun 28, 2017, 9:26 AM EDT
Vivek KumarRank #272 · 9.3K reputationPosted Jun 28, 2017, 2:30 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts