It is not possible to use it. You need to use IHostingEnvironment for Core 2.0 and IWebHostEnvironment for Core 3.0 onwards.
You will need to inject a dependency in Controller as shown below.
WebRootPath is the path of the www folder in the solution and the Uploads folder will be created inside it.
public class HomeController : Controller
{
private IHostingEnvironment Environment;
public HomeController(IHostingEnvironment _environment)
{
Environment = _environment;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public IActionResult Index(List<IFormFile> postedFiles)
{
string path = Path.Combine(this.Environment.WebRootPath, "Uploads");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
return View();
}
}