s

system.web.httppostedfile equivalent in asp .net 5.0 core mvc edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 26 February 2021 | 4183

what is the system.web.httppostedfile equivalent in asp .net 5.0 core MVC . I was upgrading an application from asp .net mvc to asp .net core 5.0 mvc. system.web.httppostedfile is no more available in asp .net core mvc.

Solution

HttpPostedFileBase doesn't exist in ASP.NET Core. You should use IFormFile now, instead

System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
System.Web.HttpPostedFile file = files[i];

replace with


IFormFileCollection files = HttpContext.Request.Form.Files;
IFormFile file = files[0];