R
R
Roman Rakzin2017-10-11 23:00:02
C++ / C#
Roman Rakzin, 2017-10-11 23:00:02

Why don't HttpPostedFileBase file and Request.File exist? How to upload a file in C#?

How to upload a file to Aps Net Core server?
I'm trying as they say, but HttpPostedFileBase file and Request.File don't exist?
What needs to be connected to receive files?

[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files) {
  foreach (var file in files) {
    if (file.ContentLength > 0) {
      var fileName = Path.GetFileName(file.FileName);
      var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
      file.SaveAs(path);
    }
  }
  return RedirectToAction("Index");
}

and in general Request.Files does not exist ... that is, it does not see Files

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter, 2017-10-12
@petermzg

In .Net Core - IFormFile and IFormFileCollection
Example here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question