Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do you upload a pdf file in MVC5?
Posted
Comments
Thanks7872 29-Jul-15 9:46am    
Just like millions of other developers do.

1 solution

namespace Template.MVC5.Controllers
{
public class FileLoadController : Controller
{

private readonly FileloadBusiness _db = new FileloadBusiness();

public ActionResult Index()
{
var x = new FileloadBusiness();
return View(x.GetAll());
}



public ActionResult Creating()
{
return View();
}

[HttpGet]
public ActionResult Uploaded()
{
ViewBag.Message = "doc";
return View();
}
[HttpPost]
public ActionResult Uploaded(FileloadView model)
{
return RedirectToAction("CustHome", "Customer");
}


[HttpPost]
public ActionResult Creating(FileloadView doc)
{
try
{
_db.Insert(doc);

return RedirectToAction("Uploaded");
}
catch (Exception e)
{

return View();
}
}

DataContext db = new DataContext();

public ActionResult Download()
{
return View(_db.GetAll());
}

public FileContentResult FileDownload(int? id)
{
byte[] fileData;
string fileName;

var x = new FileloadBusiness();
var fileRecord = db.FileLoads.Find(id);


fileData = (byte[])fileRecord.File.ToArray();
fileName = fileRecord.FileName;


return File(fileData, "text", fileName);


}

}
}
 
Share this answer
 

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