I need to list all files that are present in a given folder, using C# for ASP.Net core 1. Something like System.IO.Directory.GetFiles()
in earlier versions.
To enumerate directories and files, use methods that return an enumerable collection of directory or file names, or their DirectoryInfo, FileInfo, or FileSystemInfo objects. If you want to search and return only the names of directories or files, use the enumeration methods of the Directory class.
Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method.
First, the File is read as Binary Data into a Byte Array object using the ReadAllBytes method of the File class. And then the Byte Array object is sent for download using the File function. //Fetch all files in the Folder (Directory). string[] filePaths = 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With