I want to access the locally stored files in a particular folder in my wwwroot and display them on a view.
I can see the files using the IDirectoryContents object but I can't see how to look around that object and access the file names.
IFileProvider provider = new PhysicalFileProvider(_env.WebRootPath");
IDirectoryContents contents = provider.GetDirectoryContents("");
To loop around IDirectoryContents you can use the PhysicalFileInfo class.
using Microsoft.Extensions.FileProviders.Physical;
foreach (PhysicalFileInfo myFile in contents)
{
string filename = myFile.Name;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.