3
Utilize Enumeratefiles to get the files from a given directory by configuring the third parameter System.IO.SearchOption.AllDirectories
so that the search is done in all directories.
string path = HttpContext.Current.Server.MapPath("~//Arquivos//Uploads");
IEnumerable<string> files = System.IO.Directory.EnumerateFiles(path,
"*.*",
System.IO.SearchOption.AllDirectories);
Observing: System.IO.Directory.GetFiles
can also be used in the same way having also 3 pan the same definition of System.IO.SearchOption.AllDirectories
.
System.IO.Directory.Getfiles(
path
, "*.*
",System.IO.SearchOption.AllDirectories
);
Using Linq can work better 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:
worked beautifully. However, the answer I have is the way
C:\Users\renan.carlos\Source\Repos\CodingCraft\ExerciciosCodingCraft\MusicFileServer.API\Arquivos\Uploads\docx\Coding Craft ASP.NET MVC 1.docx
To get just the file name, I need to give a Replace from the end to the beginning until the first bar ? Or has a better way to do? You’d rather I ask a new question ?– Renan Carlos
@Renancarlos did the editing!
– novic