title: How to upload files in ASP.NET MVC 5 to Database
body: <p>I am trying to implement a file upload to my existing project. I have a reports table within my database and it contains a FilePath column.</p>
  
  <pre><code>public string FilePath {get; set;}
  </code></pre>
  
  <p>I have an existing Save action that handles both new and existing entries:</p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  [Authorize(Roles = "AdminManager")]
  public ActionResult Save(Report report, HttpPostedFileBase file)
  {
      if (!ModelState.IsValid)
      {
          var viewModel = new ReportFormViewModel
          {
              Report = report,
              Members = _context.Members.ToList(),
              Subjects = _context.Subjects.ToList()
          };
          return View("ReportForm", viewModel);
      }
  
      if (report.Id == 0)
          _context.Reports.Add(report);
  
      else
      {
          var reportInDb = _context.Reports.Single(e =&gt; e.Id == report.Id);
  
          reportInDb.Name = report.Name;
          reportInDb.MemberId = report.MemberId;
          reportInDb.SubjectId = report.SubjectId;
          reportInDb.Date = report.Date;
      }
  
      _context.SaveChanges();
      return RedirectToAction("Index", "Report");
  }
  </code></pre>
  
  <p>I have already changed the form view to take a file so all that needs updating is the controller. I tried to find examples online but they mostly implemented it into a create action rather then what I have.</p>