A nuget package that provides a class SortedHtmlDirectoryFormatter derived from HtmlDirectoryFormatter Link, which will render the file list sorted by the LastModified property in descending order.
dotnet add package SortedHtmlDirectoryFormatterpublic void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseDirectoryBrowser(new DirectoryBrowserOptions
{
FileProvider = new PhysicalFileProvider(rootDirectory),
RequestPath = "/your-request-path",
Formatter = new SortedHtmlDirectoryFormatter()
});
}The extension method UseDirectoryBrowser generates a table that sorts the output by filename. This is not a super helpful behavior when it comes to some scenarios. e.g. Directory Browser on a folder full of files with random file names.
According to this github issue there is no plan to add a feature to sort this.
Hence I created this nuget package for this.
Another related github issue:
dotnet/aspnetcore#29539