I'm quite new to MVC and doing a To Do List Web application. I want to allow users to attach a file to the task. I've read that I need to store it in a byte type variable.
My controller :
public ActionResult AddTask (TaskModel t, HttpPostedFileBase file)
{
if (Session["UserID"] != null)
{
using (ToDoListEntities3 context = new ToDoListEntities3())
{
FilesTable ff = new FilesTable();
t.fileId = Convert.ToInt32(Session["UserID"]);
ff.FileId = t.fileId;
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
ff.FileName = fileName;
var content = new byte[file.ContentLength];
file.InputStream.Read(content, 0, file.ContentLength);
ff.File = content;
}
I was able to store the ID and the Filename, but I don't quite understand how the FILES are stored in the db. What does it mean to convert a file to byte?