ASP.Net core 1 list files in given directory

you can do something like this:

foreach (string file in Directory.EnumerateFiles(
            pathToFolder, 
            "*" , 
            SearchOption.AllDirectories) 
            )
        {
            // do something

        }

note that I'm recursing child directories too which may or may not be what you want


in asp.net core to list or search files you can use this way:

for example consider we want to find latest update file in this directory:

public IActionResult Get(IFileProvider fileProvider)
 {
      var files = fileProvider.GetDirectoryContents("wwwroot/updates");

      var latestFile =
                files
                .OrderByDescending(f => f.LastModified)
                .FirstOrDefault();

      return Ok(latestFile?.Name);
 }