In this example, I have told you how to get all Files list from a specific directory using Linq query. File Info Class which will return the history of file e.g. (creation, modify date, opening of files, last access date etc.)
Here’s is the solution.
Default.aspx Page
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to get All Files list from a directory using Linq query</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>How to get All Files list from a directory using Linq query</h2>
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
Default.aspx.cs Page
protected void Page_Load(object sender, EventArgs e)
{
string DirPath = Server.MapPath("Scripts");
System.IO.FileInfo[] Files = new System.IO.DirectoryInfo(DirPath).GetFiles();
var FileDetails = from file in Files
select new
{
FileName = file.Name,
CreatedDate = file.CreationTime.ToString("MM/dd/yyyy"),
Size = file.Length / 1024
};
foreach (var u in FileDetails)
Label1.Text +=
"<strong>File Name: </strong> " + u.FileName +
"<br><strong>Created Date:</strong>" + u.CreatedDate +
"<br><strong>Size:</strong>" + u.Size + " KB" +
"<br><br>";
}
Output

Download
get_All_Files.zip (127.70 kb)
Live demo