Hai friends,
How to save the images in solution explorer & its path in database.
& should be able to download.
please provide me solution.
Thank you.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manoj BhoirRank #599 · 4K reputationPosted Apr 18, 2015, 1:31 AM EDT
Model :
public class MyViewModel
{
[Required]
public HttpPostedFileBase File { get; set; }
}
Controller :
public class HomeController: Controller
{
public ActionResult Index()
{
var model = new MyViewModel();
return View(model);
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
byte[] uploadedFile = new byte[model.File.InputStream.Length];
model.File.InputStream.Read(uploadedFile, 0, uploadedFile.Length);
// now you could pass the byte array to your model and store wherever
// you intended to store it
return Content("Thanks for uploading the file");
}
}
View :
@model MyViewModel
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.LabelFor(x => x.File)
@Html.TextBoxFor(x => x.File, new { type = "file" })
@Html.ValidationMessageFor(x => x.File)
}
Reference : http://stackoverflow.com/questions/15106190/uploading-files-into-database-with-asp-net-mvc
Vijay Saklani147 reputationPosted Apr 24, 2015, 10:44 PM EDT
Controller:
View :
If you get any problem to implement . visit the the below given link:
http://www.articlemirror.in/2014/02/file-upload-and-save-path-to-database.html
Vincent Maverick DuranoRank #238 · 10.3K reputationPosted Apr 25, 2015, 11:22 PM EDT
Googling the term should give you lots of examples in the web, here are some of them:
http://byatool.com/mvc/asp-net-mvc-upload-image-to-database-and-show-image-dynamically-using-a-view/
http://www.codeproject.com/Articles/708140/Uploading-and-Viewing-Images-With-ASP-Net-MVC-and