What is the alternative of HttpContext.Current.Request.Files in asp .net core 5.0 mvc Edit

Murugan Andezuthu Dharmaratnam | 26 February 2021 | 169

I was upgrading an asp .net MVC application to an asp .net core MVC 5.0 application. System.Web.HttpContext.Current.Request.Files was not available in asp .net core mvc 5.0 application.

Solution

You can use IFormFileCollection files = HttpContext.Request.Form.Files; insted of System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files in you asp .net core 5.0 mvc application.


System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;

replace above line with

IFormFileCollection files = HttpContext.Request.Form.Files;