Sorting files from directoryinfo by date in asp.net

Frank picture Frank · Oct 12, 2011 · Viewed 18k times · Source

how can I sort (not filter) directoryinfo files by date (oldest to recent) ? I am using asp.net and visual studio 2008

Answer

apros picture apros · Oct 12, 2011

The same as @DaRKoN_ in 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