Live Chat Icon For mobile
Live Chat Icon

How to get list of all files in the directory

Platform: ASP.NET| Category: Miscellaneous

To get the list of aspx files under your app directory:

Use namespace System.IO


Dim dirInfo As New DirectoryInfo(Server.MapPath(''))
DataGrid1.DataSource = dirInfo.GetFiles('*.aspx')


DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(''));
DataGrid1.DataSource = dirInfo.GetFiles('*.aspx');

The following aspx code will display the resultant files list in the DataGrid in a proper format:

<asp:DataGrid runat='server' id='DataGrid1' AutoGenerateColumns='False'>
<asp:HyperLinkColumn DataNavigateUrlField='Name' DataTextField='Name' HeaderText='File Name'></asp:HyperLinkColumn>
<asp:BoundColumn DataField='LastWriteTime' HeaderText='Last Write Time' DataFormatString='{0:d}'></asp:BoundColumn>
<asp:BoundColumn DataField='Length' HeaderText='File Size' DataFormatString='{0:#,### bytes}'></asp:BoundColumn>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.