Sort files from the info directory by date in asp.net

How can I sort (not filter) catalog files by date (from old to recent)? I am using asp.net and visual studio 2008

+4
source share
3 answers

Same as @DaRKoN_ on vb.net:

Module Module1 Sub Main() Dim orderedFiles = New System.IO.DirectoryInfo("c:\\").GetFiles().OrderBy(Function(x) x.CreationTime) For Each f As System.IO.FileInfo In orderedFiles Console.WriteLine(String.Format("{0,-15} {1,12}", f.Name, f.CreationTime.ToString)) Next End Sub End Module 
+8
source

The GetFiles() method in the DirectoryInfo class returns an array that implements IEnumerable. This way you can apply all the standard LINQ extension methods.

 var orderedFiles = new System.IO.DirectoryInfo("path") .GetFiles() .OrderBy(x => x.CreationTime); 

Edit: just realized that this is labeled VB. Also see John Comment on OP re: existing answers.

+4
source

It was tagged vb (which is why I came across it.) I thought I would drop the vb answer there.

  Dim sDir As String = HttpRuntime.AppDomainAppPath Dim oDirInfo As System.IO.DirectoryInfo Dim oInfo As System.IO.FileInfo oDirInfo = New System.IO.DirectoryInfo(sDir) oInfo = oDirInfo.GetFiles().OrderByDescending(Function(p) p.LastWriteTime).First() return oInfo.LastWriteTime 
0
source

All Articles