I want to return 10 files only from a directory. Is this possible?
DirectoryInfo d = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/xml"));
FileInfo[] files = d.GetFiles("*.xml");
This way returns all XML files, but I want to get just the first ten.
You can add the extension method Take(10) to only grab the first 10 files.
var d = new DirectoryInfo(HttpContext.Current.Server.MapPath("~/xml"));
var files = d.GetFiles("*.xml").OrderByDescending(fi=>fi.LastWriteTime).Take(10);
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