Getting the lists of all files in the directory.

vishalneeraj-24503
Posted by vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 395
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">  
<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>

'VB/Net
Dim dirInfo As New DirectoryInfo(Server.MapPath(""))
grid_files.DataSource = dirInfo.GetFiles("*.aspx")
grid_files.DataBind()

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

Comments or Responses

Login to post response