How to read files in a directory and get file by date created or time created using VB.NET System.IO getFiles, File.getCreationTime and how to make a DateTime

'In this particular code example, I am building a dynamic iFrame that loads a pdf which is 'embedded in the page. You can ignore the vars and focus on the code in red


Dim newsletterDir As String = "~\myNews\Newsletter"
Dim filePaths As String() = Directory.GetFiles(Server.MapPath(newsletterDir))
Dim newsletterSrc As String = ""
Dim compareDatTime As DateTime = New DateTime(2000, 2, 1)
For Each filePath As String In filePaths
Dim fileName As String = System.IO.Path.GetFileName(filePath)
Dim fileDate As DateTime = File.GetCreationTime(filePath)

'don't ever use the system thumbs.db file
If Not fileName = "Thumbs.db" Then

If fileDate > compareDatTime Then

newsletterSrc = "myNews/Newsletter/" & fileName

compareDatTime = fileDate

End If

End If
iframe = iframeStart & newsletterSrc & iframeEnd
litIframe.Text = iframe
LoadExternalSite = True
hypLoadExtSite.Text = "OPEN IN NEW WINDOW"
hypLoadExtSite.NavigateUrl = newsletterSrc
pnlLoadExternalSite.Visible = True

Tags: date, System.IO, VB
Last update:
2015-06-03 21:42
Average rating:0 (0 Votes)

You can comment this FAQ

Chuck Norris has counted to infinity. Twice.

Records in this category