Getting the lists of all files in the directory.

Posted by vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 715
Suppose,we have datagrid,and we have also some files which we want to show on datagrid,then we will write below code as:-
<asp:DataGrid runat = "server" Id = "grid_files" 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>

Dim dirInfo As New DirectoryInfo(Server.MapPath(""))
grid_files.DataSource = dirInfo.GetFiles("*.aspx")

DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(""));
grid_files.DataSource = dirInfo.GetFiles("*.aspx");

Comments or Responses

Login to post response