I have created a images folder inside my wwwroot. The Images folder also have subfolders. I want to get these subfolders so I can send them into view using ViewBag but I don't know how to reach them.
private string mainDirectory;
public TestController(IWebHostEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
mainDirectory = Path.Combine(Directory.GetCurrentDirectory(), _hostingEnvironment.WebRootPath, "images");
string[] files = Directory.GetFiles(mainDirectory)
.Select(f => Path.GetFileName(f))
.ToArray();
}
I managed to get the files inside images folder with the code above (string[] files) but I need subfolders not files.