Use EnumerateFiles to get the files from a given directory , setting the third parameter System.IO.SearchOption.AllDirectories
so that the search is done in every directory.
string path = HttpContext.Current.Server.MapPath("~//Arquivos//Uploads");
IEnumerable<string> files = System.IO.Directory.EnumerateFiles(path,
"*.*",
System.IO.SearchOption.AllDirectories);
Note: System.IO.Directory.GetFiles
" can also be used in the same way also having 3 same definition of System.IO.SearchOption.AllDirectories
.
System.IO.Directory.GetFiles ( path
, "% *.*
);
Using Linq can work on this information and get only the name of the files:
var result = System.IO.Directory.EnumerateFiles(path,
"*.*",
System.IO.SearchOption.AllDirectories)
.Select(c =>
c.Split(new string[] { "\" }, StringSplitOptions.None).Last())
.ToArray();
References: