Sorry for a noob question, but it seems I can\'t get Server.MapPath from Controller. I need to output json file list from images folder at wwwroot. They are is at wwwroot/im
You will need to inject IHostingEnvironment
into your class to have access to the ApplicationBasePath
property value: Read about Dependency Injection. After successfully injecting the dependency, the wwwroot path should be available to you. For example:
private readonly IHostingEnvironment _appEnvironment;
public ProductsController(IHostingEnvironment appEnvironment)
{
_appEnvironment = appEnvironment;
}
Usage:
[HttpGet]
public IEnumerable Get()
{
FolderScanner scanner = new FolderScanner(_appEnvironment.ApplicationBasePath);
return scanner.scan();
}