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

VB.NET


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

C#


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

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'>
<Columns>
<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>
</Columns>
</asp:DataGrid>

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

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

Please submit your question and answer.