display a file list to enable downloading

P

Paul Wilson

How do i display the list of files in a particular directory (only the file
name), in a grid or similar control, with hyperlinks to be able to download
those files.

Regards,
Paul
 
G

Guest

Hi Paul,

U can use the DirectoryInfo.GetFiles() method to get the list of files in the directory and then bind the result to a datagrid. Here's some sample code:

//to be put in the codebehind file
DirectoryInfo di=new DirectoryInfo("C:\\");
FileInfo[] fi=di.GetFiles();
DataGrid1.DataSource=fi;
DataGrid1.DataBind();

//in the aspx file
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns=false>
<Columns>
<asp:BoundColumn HeaderText="Name" DataField="Name"/>
<asp:BoundColumn HeaderText="Date Created" DataField ="CreationTime" />
</Columns>
</asp:DataGrid>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top